Guardian Native C Library Calls Reference Manual (G06.28+, H06.04+)

Guardian Native C Library Calls (s) setlocale(3)
3. The following subroutine queries and saves the existing international environment, then
explicitly sets the locale to the C locale, performs some operations in the C locale, and
nally, restores the locale to the saved environment. The main program typically uses
setlocale() to set the international environment to the locale speci
ed by the users
environment program. If a subroutine needs to execute in a specic locale, it must save
and restore the international environment.
#include <locale.h>
#include <string.h>
void Do_stuff(void)
{
char *test_l, *saved_l;
test_l=setlocale(LC_ALL,NULL);
saved_l=strdup(test_l);
test_l=setlocale(LC_ALL,"C");
/* Perform operations in the C locale */
/* Restore the original locale */
test_l=setlocale(LC_ALL,saved_l);
return;
}
RETURN VALUES
If the setlocale() function succeeds in setting the programs locale to the one specied by the
locale parameter, it returns the string associated with the specied category parameter for the
new locale. Note that the locale parameter can specify the locale name explicitly or, if it is a null
string, by the corresponding environment variable. If the setlocale() function cannot set the
programs locale as requested, it returns a null pointer and leaves the programs locale
unchanged.
If the category parameter has a value of LC_ALL, the return value is a series of locale names
separated by spaces. The locale names correspond to the categories in the following order:
LC_COLLATE
LC_CTYPE
LC_MONETARY
LC_NUMERIC
LC_TIME
LC_MESSAGES
If the locale parameter is a null pointer, the setlocale() function returns the string associated with
the category parameter for the programs current locale, and leaves the programs locale
unchanged.
The string returned by the setlocale( ) function is such that a subsequent call with that string and
its associated category restores that part of the programs locale. The string returned must not be
modied by the program, but is overwritten by a subsequent call to the setlocale( ) function.
527192-005 Hewlett-Packard Company 617