setlocale.3c (2010 09)

s
setlocale(3C) setlocale(3C)
The string returned by setlocale() is such that a subsequent call with that string as the locale argu-
ment and its associated category restores that part of the programs locale.
ERRORS
If a language name given through the locale argument does not identify a valid language name, or if the
language name is more than 256 characters, or if the language is not available on the system (see
lang(5)), then a null pointer is returned and the programs locale is not changed. The same behavior
occurs when the call:
setlocale(LC_ALL, "");
is made and any category related environment variable in the user’s environment identifies an invalid
language name or a language that is not available on the system.
If the category argument is not a defined category value, a null pointer is returned and the programs
locale is not changed.
setlocale() returns a string that reflects the current setting of that aspect of the NLS environment
corresponding to the category argument. If this return string is used in a subsequent
setlocale() call
and the category arguments of the two calls do not match, the locale remains unchanged and a null
pointer is returned.
EXAMPLES
To set a program’s entire locale based on the language requirements specified via the user’s environment
variables:
setlocale(LC_ALL, "");
If in the example the user’s environment variables were set as follows:
LANG ="de_DE.iso88591"
LC_COLLATE ="es_ES.iso88591"
LC_MONETARY =""
LC_TIME ="en_US.iso88591"
the LC_CTYPE, LC_MONETARY, and LC_NUMERIC category items would be set to correspond to the
de_DE.iso88591 language definition, the
LC_COLLATE category items would be set to correspond to
the
es_ES.iso88591 language definition for collation and the
LC_TIME category items would be set
corresponding to the
en_US.iso88591
language definition.
Using the same example, if the following call was made:
struct locale_data *locale_info=getlocale(LOCALE_STATUS);
the contents of *locale_info would be:
locale_info->LC_ALL_D="de_DE.iso88591"
locale_info->LC_COLLATE_D="es_ES.iso88591"
locale_info->LC_CTYPE_D="de_DE.iso88591"
locale_info->LC_MESSAGES_D="de_DE.iso88591"
locale_info->LC_MONETARY_D="de_DE.iso88591"
locale_info->LC_NUMERIC_D="de_DE.iso88591"
locale_info->LC_TIME_D="en_US.iso88591"
The next example shows the precedence of the LC_ALL environment variable:
setlocale(LC_ALL, "");
with the following settings in the user’s environment:
LANG=de_DE.iso88591
LC_ALL=fr_FR.iso88591
All categories will be loaded with fr_FR.iso88591.
Another example showing the precedence of the
LC_ALL environment variable:
setlocale(LC_CTYPE, "");
with the following settings in the user’s environment:
LANG=tr_TR.iso88599
LC_ALL=da_DK.iso88591
HP-UX 11i Version 3: September 2010 3 Hewlett-Packard Company 3