Mailing List Archive

setlocale(), LC_CTYPE
As Larry correctly pointed out, setlocale(LC_CTYPE, "") is probably
better than fetching the "LC_CTYPE" env var explicitly (suggested in
my patch). "" is a magic string to setlocale() that means (quoting
from several vendors' man pages):

"" Specifies that the locale should be set based on the user's
current values for the locale environment variables.

"" Specifies categories be set according to locale environment
variables.

"" If the value of locale is the empty string, the
setting of that part of the NLS environment
associated with category depends on the setting of
the following environment variables in the user's
environment (see environ(5)):

LANG LC_MESSAGES
LC_ALL LC_MONETARY
LC_COLLATE LC_NUMERIC
LC_CTYPE LC_TIME

If category is any defined value other than LC_ALL,
setlocale() sets that category as specified by the
value of the LC_ALL environment or if LC_ALL is not
set to the corresponding environment variable. If
the environment variable is not set or set to the
empty string, setlocale() sets the category as
specified by the value of the LANG environment
variable. If LANG is not set or is set to the empty
string, then setlocale() sets the category to the "C"
locale. For example, setlocale(LC_TIME,"") sets the
program's NLS environment associated with the LC_TIME
category to the value specified by the user's LC_TIME
environment variable. All other aspects of the NLS
environment are unaffected.

If category is LC_ALL, then all categories are set
corresponding to the value of LC_ALL if LC_ALL is
set, or LANG if LC_ALL is not set, except for those
categories in which the corresponding environment
variable is set to a valid language name (see
lang(5)). In this case the value of the environment
variable overrides the values of LC_ALL and LANG for
that category. If the values of both LC_ALL and LANG
are not set or are set to the empty string, then the
"C" locale is used.

The following usage of setlocale() results in the
program's locale being set according to the the
user's language requirements:

setlocale(LC_ALL,"");

So the getenv() magic seems to be built-in to setlocale().

++jhi;