mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: "Remko Tronçon" <remko@el-tramo.be>
Cc: musl@lists.openwall.com
Subject: Re: How to set UTF-8 as default
Date: Thu, 2 Jun 2016 11:01:54 -0400	[thread overview]
Message-ID: <20160602150154.GJ10893@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAJpZQQ6jjQbRRM5Bdr-NwLn4UqsHxbWwnd_EKYhj2Uv7507Aqg@mail.gmail.com>

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


  parent reply	other threads:[~2016-06-02 15:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-02 11:05 Remko Tronçon
2016-06-02 14:50 ` FRIGN
2016-06-02 15:03   ` Rich Felker
2016-06-02 15:01 ` Rich Felker [this message]
2016-06-02 15:40   ` Remko Tronçon
2016-06-02 17:10     ` Markus Wichmann
2016-06-02 17:32       ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160602150154.GJ10893@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    --cc=remko@el-tramo.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).