Next: setlogmask
, Previous: setkey
, Up: ISO C and POSIX Function Substitutes [Contents][Index]
setlocale
POSIX specification:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/setlocale.html
Gnulib module: setlocale, setlocale-null
Portability problems fixed by Gnulib module setlocale
:
setlocale(category,"")
and setlocale(category,NULL)
both ignore the environment variables
LC_ALL
, category
, and LANG
.
setlocale(LC_ALL,name)
succeeds and sets the LC_CTYPE category to
‘C’ when it does not support the encoding, instead of failing.
setlocale
understands different
locale names, that are not based on ISO 639 language names and ISO 3166 country
names.
setlocale
function
always fails. The replacement, however, supports only the locale names
"C"
and "POSIX"
.
Portability problems fixed by Gnulib module setlocale
or setlocale-null
:
setlocale (..., NULL)
are not multithread-safe on some
platforms:
musl libc, macOS, FreeBSD, NetBSD, OpenBSD, AIX, Haiku, Cygwin.
To make these invocations multithread-safe, you need the Gnulib module
setlocale
, or you need to change the code to invoke setlocale_null
or setlocale_null_r
instead.
Portability problems not fixed by Gnulib:
setlocale(LC_ALL,NULL)
always returns "C"
.
setlocale(LC_ALL,"")
will only update categories that
are deemed appropriate for the LC_ALL
environment value, even if
there are other categories set to different values in the environment.
In addition any value is accepted for LC_CTYPE
, and so NULL
is never returned to indicate a failure to set locale.
To verify category values, each category must be set individually
with setlocale(LC_COLLATE,"")
etc.
setlocale
was not called) is the "C.UTF-8"
locale, not the
"C"
locale. Additionally, a setlocale
call that is meant to set
the "C"
or "POSIX"
locale actually sets an equivalent of the
"C.UTF-8"
locale.
Next: setlogmask
, Previous: setkey
, Up: ISO C and POSIX Function Substitutes [Contents][Index]