From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10076 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: How to set UTF-8 as default Date: Thu, 2 Jun 2016 11:01:54 -0400 Message-ID: <20160602150154.GJ10893@brightrain.aerifal.cx> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1464879740 17071 80.91.229.3 (2 Jun 2016 15:02:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 2 Jun 2016 15:02:20 +0000 (UTC) Cc: musl@lists.openwall.com To: Remko =?utf-8?Q?Tron=C3=A7on?= Original-X-From: musl-return-10089-gllmg-musl=m.gmane.org@lists.openwall.com Thu Jun 02 17:02:17 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1b8U8W-0007aG-Dn for gllmg-musl@m.gmane.org; Thu, 02 Jun 2016 17:02:16 +0200 Original-Received: (qmail 8110 invoked by uid 550); 2 Jun 2016 15:02:14 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 8090 invoked from network); 2 Jun 2016 15:02:13 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:10076 Archived-At: On Thu, Jun 02, 2016 at 01:05:40PM +0200, Remko Tronçon wrote: > Hi, > > When I call `nl_langinfo`, it returns "ASCII" by default. I can call > `setlocale(LC_CTYPE, "C.UTF-8")` to make it return "UTF-8", but I was > wondering if there was a way through environment variables to make C.UTF-8 > be the default. Just call setlocale(LC_CTYPE, ""). This is the only way a correct program should ever use setlocale. Specifying the locale name yourself is not portable and generally contrary to the user's intent and expectations. Passing "" requests the "default" locale, which is implementation-defined by C. POSIX defines it in terms of the LC_* and LANG environment variables if they are set, and an implementation-defined default otherwise. musl's implementation-defined default is C.UTF-8, so everythin works fine even if no env vars are set. > I tried setting LC_CTYPE and LC_ALL to C.UTF-8, but this doesn't seem to > get picked up by `nl_langinfo` (or by `setlocale(LC_CTYPE, NULL)`). NULL is not the same thing as "". Passing NULL as the second argument to setlocale simply queries the current locale name. It does not setup the locale. Rich