function is used to set or query the program's current locale.
is not NULL,
the program's current locale is modified according to the arguments.
determines which parts of the program's current locale should be modified.
for all of the locale.
for regular expression matching (it determines the meaning
of range expressions and equivalence classes) and string collation.
for regular expression matching, character classification, conversion,
case-sensitive comparison, and wide character functions.
for localizable natural-language messages.
for monetary formatting.
for number formatting (such as the decimal point and the thousands separator).
for time and date formatting.
is a pointer to a character string containing the
required setting of
Such a string is either a well-known constant like "C" or "da_DK"
(see below), or an opaque string that was returned by another call of
each part of the locale that should be modified is set according to the
The details are implementation-dependent.
For glibc, first (regardless of
the environment variable
next the environment variable with the same name as the category
and finally the environment variable
The first existing environment variable is used.
If its value is not a valid locale specification, the locale
is unchanged, and
is a portable locale; its
part corresponds to the 7-bit ASCII
A locale name is typically of the form
is an ISO 639 language code,
is an ISO 3166 country code, and
is a character set or encoding identifier like
For a list of all supported locales, try "locale -a", cf.
is NULL, the current locale is only queried, not modified.
On startup of the main program, the portable
locale is selected as default.
A program may be made portable to all locales by calling:
after program initialization, by using the values returned
for locale-dependent information, by using the multibyte and wide
character functions for text processing if
MB_CUR_MAX > 1,
and by using
to compare strings.
A successful call to
returns an opaque string that corresponds to the locale set.
This string may be allocated in static storage.
The string returned is such that a subsequent call with that string
and its associated category will restore that part of the process's
The return value is NULL if the request cannot be honored.
C89, C99, POSIX.1-2001.
Linux (that is, glibc) supports the portable locales
"C" and "POSIX".
In the good old days there used to be support for
the European Latin-1
locale (e.g., in libc-4.5.21 and libc-4.6.27), and the Russian
(more precisely, "koi-8r") locale (e.g., in libc-4.6.27),
so that having an environment variable LC_CTYPE=ISO-8859-1
sufficed to make
return the right answer.
These days non-English speaking Europeans have to work a bit harder,
and must install actual locale files.