diff options
author | Ruslan Ermilov <ru@FreeBSD.org> | 2001-03-02 12:45:52 +0000 |
---|---|---|
committer | Ruslan Ermilov <ru@FreeBSD.org> | 2001-03-02 12:45:52 +0000 |
commit | 825d095dd3c17a63a6804cc2b41d47c95c0f1de0 (patch) | |
tree | 5f0d45d88bc4d068fc05ae43aec3446277af830a | |
parent | 0d42ab242ed362fe8bc1a3d8b88600e68d2b69f0 (diff) | |
download | src-825d095dd3c17a63a6804cc2b41d47c95c0f1de0.tar.gz src-825d095dd3c17a63a6804cc2b41d47c95c0f1de0.zip |
Fix setlocale() to conform to the ISO C and POSIX standards.
The below text is quoted from the latest POSIX draft:
: The values of locale categories shall be determined by a precedence
: order; the first condition met below determines the value:
:
: 1. If the LC_ALL environment variable is defined and is not null,
: the value of LC_ALL shall be used.
: 2. If the LC_* environment variable (LC_COLLATE, LC_CTYPE, LC_MESSAGES,
: LC_MONETARY, LC_NUMERIC, LC_TIME) is defined and is not null, the
: value of the environment variable shall be used to initialize the
: category that corresponds to the environment variable.
: 3. If the LANG environment variable is defined and is not null, the
: value of the LANG environment variable shall be used.
: 4. If the LANG environment variable is not set or is set to the empty
: string, the implementation-defined default locale shall be used.
The conditions 1 and 2 were interchanged, i.e., LC_* were looked first,
then LC_ALL, then LANG (note that LC_ALL and LANG were essentially the
same, providing the default, with LC_ALL taking precedence over LANG).
Now, LC_ALL and LANG serve the different purposes. LC_ALL overrides
any LC_*, and LANG provides the default fallback.
Testcase:
/usr/bin/env LC_ALL=C LC_TIME=de_DE.ISO_8859-1 /bin/date
Should return date in the "C" locale format.
Inspired by: date(1) reference page in the Draft
Notes
Notes:
svn path=/head/; revision=73340
-rw-r--r-- | lib/libc/locale/setlocale.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index ccae90607eac..825a2fb07c28 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -124,10 +124,10 @@ setlocale(category, locale) * Now go fill up new_categories from the locale argument */ if (!*locale) { - env = getenv(categories[category]); + env = getenv("LC_ALL"); if (category != LC_ALL && (!env || !*env)) - env = getenv(categories[LC_ALL]); + env = getenv(categories[category]); if (!env || !*env) env = getenv("LANG"); |