Guardian Native C Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

setlocale(3) Guardian Native C Library Calls Reference Manual
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
finally, restores the locale to the saved environment. The main program typically uses
setlocale() to set the international environment to the locale specified by the user’s
environment program. If a subroutine needs to execute in a specific 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 program’s locale to the one specified by the
locale parameter, it returns the string associated with the specified 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
program’s 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 program’s 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 program’s locale. The string returned must not be
modified by the program, but is overwritten by a subsequent call to the setlocale() function.
632 Hewlett-Packard Company 527192-018