This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: nl_langinfo(CODESET) question


Jakub Jelinek <jakub@redhat.com> writes:

> If setlocale does not find locale with the requested charset, then it just
> uses the charset stored in the locale, eventhough libc is able to
> transliterate.
> I'm wondering whether
> setlocale (LC_ALL, "cs_CZ.UTF-8");
> shouldn't result in nl_langinfo(CODESET) == "UTF-8" as opposed to
> "ISO-8859-2" even if the installed locale is latin2 only.

Well, this would be ideal but is far too costly.  It would mean that
the __ctype_b table would have to be transformed on-the-fly (and many
other pieces of information).  This is not realistic.

But I realize and was aware of this problem.  For quite sometime I
wanted to implement something.  What I have in mind is that the
setlocale() function actually fails if the locale data which is found
is using a different charset than the one specified in the locale
variable.

I.e., the locale data is searched as before.  But before the locale is
switched and if the LC_ALL etc. value contains a charset name we first
test whether the locale data charset and the charset in LC_ALL are the
same (using the gconv alias file).  If not, setting the locale fails.
This is the correct solution since there definitely is no such locale
available.

> I've tried this on Solaris and if I specify a codeset that is not installed
> for a selected locale, nl_langinfo(CODESET) returns "646" as opposed to e.g.
> "ISO8859-2" which it returns otherwise.

Don't compare glibc with Solaris.  Their locale implementation is very
different and does not offer all these nice things which make life
harder for us.


I'll hopefully get to fixing this tomorrow.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]