setlocale sets the current locale for category
category to locale. A list of all the locales the system
provides can be created by running
If category is
LC_ALL, this specifies the locale for all
purposes. The other possible values of category specify an
single purpose (see Locale Categories).
You can also use this function to find out the current locale by passing
a null pointer as the locale argument. In this case,
setlocale returns a string that is the name of the locale
currently selected for category category.
The string returned by
setlocale can be overwritten by subsequent
calls, so you should make a copy of the string (see Copying and Concatenation) if you want to save it past any further calls to
setlocale. (The standard library is guaranteed never to call
You should not modify the string returned by
setlocale. It might
be the same string that was passed as an argument in a previous call to
setlocale. One requirement is that the category must be
the same in the call the string was returned and the one when the string
is passed in as locale parameter.
When you read the current locale for category
LC_ALL, the value
encodes the entire combination of selected locales for all categories.
In this case, the value is not just a single locale name. In fact, we
don't make any promises about what it looks like. But if you specify
the same “locale name” with
LC_ALL in a subsequent call to
setlocale, it restores the same combination of locale selections.
To be sure you can use the returned string encoding the currently selected
locale at a later time, you must make a copy of the string. It is not
guaranteed that the returned pointer remains valid over time.
When the locale argument is not a null pointer, the string returned
setlocale reflects the newly-modified locale.
If you specify an empty string for locale, this means to read the
appropriate environment variable and use its value to select the locale
If a nonempty string is given for locale, then the locale of that
name is used if possible.
If you specify an invalid locale name,
setlocale returns a null
pointer and leaves the current locale unchanged.