HP-UX Reference (11i v2 04/09) - 3 Library Functions N-Z (vol 7)

s
setlocale(3C) setlocale(3C)
"" If the value of locale is the empty string, the setting of that part of the NLS
environment associated with category depends upon the setting of the follow-
ing environment variables in the user’s environment (see environ(5)):
LANG LC_MESSAGES
LC_ALL LC_MONETARY
LC_COLLATE LC_NUMERIC
LC_CTYPE LC_TIME
If category is any defined value other than
LC_ALL, setlocale() sets that
category as specified by the value of the
LC_ALL environment. This is also
the case if
LC_ALL is not set to the corresponding environment variable. If
the environment variable is not set or is set to the empty string,
setlo-
cale() sets the category as specified by the value of the
LANG environment
variable. If
LANG is not set or is set to the empty string, then
setlocale()
sets the category to the C locale. For example,
setlocale(LC_TIME,"")
sets the program’s NLS environment associated with the
LC_TIME category to
the value specified by the user’s
LC_TIME environment variable. All other
aspects of the NLS environment are unaffected.
If category is
LC_ALL, then all categories are set corresponding to the value of
LC_ALL if LC_ALL is set, or LANG if LC_ALL is not set, except for those
categories in which the corresponding environment variable is set to a valid
language name (see lang(5)). In this case the value of the environment vari-
able overrides the values of LC_ALL and LANG for that category. If the values
of both LC_ALL and LANG are not set or are set to the empty string, then the
C locale is used.
The following usage of
setlocale() results in the program’s locale being set
according to the the user’s language requirements:
setlocale(LC_ALL,"")
Querying the Locale of a Program
setlocale() queries the current NLS environment pertaining to category , if the value of locale is
NULL. The query operation does not change the environment. The purpose of performing a query is to
save that aspect of the user’s current NLS environment associated with category, in the value returned by
setlocale(), such that it can be restored with a subsequent call to setlocale().
Restoring the Locale of a Program
To restore a category within the program locale, a
setlocale() call is made with the same category
argument and the return string of the previous
setlocale() call given as the locale argument.
getlocale() returns a pointer to a locale_data structure (see /usr/include/locale.h). The
members of the locale_data structure contain information about the setting of each setlocale()
category. type determines what information is contained in the locale_data structure. The only sup-
ported value of type is:
LOCALE_STATUS The structure member corresponding to each category contains a string with
the name of the locale currently set for that category. The string does not
include modifier information.
Obsolescent Interfaces
setlocale_r() and getlocale_r() set and get the locale of a program..
RETURN VALUE
If the pointer to a string is given for locale and the selection can be honored, the
setlocale() function
returns a pointer to the string associated with the specified category for the new locale. The maximum
length of this string is LC_BUFSIZ bytes (see <locale.h>). If the selection cannot be honored, the
setlocale() function returns a null pointer and the program’s locale is not changed.
A null pointer for locale causes
setlocale() to return a string associated with the category for the
program’s current locale.
HP-UX 11i Version 2: September 2004 2 Hewlett-Packard Company Section 3965