DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

setlocale(3C)


setlocale -- modify and query a program's locale

Synopsis

   #include <locale.h>
   

char *setlocale(int category, const char *locale);

Description

setlocale selects the appropriate piece of the program's locale as specified by the category and locale arguments. The category argument may have the following values: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL. These names are defined in the locale.h header file. LC_CTYPE affects the behavior of the character handling functions (isalpha, tolower, and so on) and the multibyte character functions (such as mbtowc and wctomb). LC_NUMERIC affects the decimal-point and thousands separator characters for the formatted input/output functions and the string conversion functions as well as the non-monetary formatting information returned by localeconv [see localeconv(3C)]. LC_TIME affects the behavior of functions such as ascftime, cftime, and strftime. LC_COLLATE affects the behavior of functions such as strcoll and strxfrm. LC_MONETARY affects the monetary formatted information returned by localeconv. LC_MESSAGES affects the behavior of functions such as gettxt, catopen, catclose, and catgets [see catopen(3C) and catgets(3C)]. LC_ALL names the program's entire locale.

Each category corresponds to a set of databases that contain the relevant information for each defined locale. The location of the system's database is given by the following path, /usr/lib/locale/locale/category, where locale and category are the names of locale and category, respectively. For example, the database for the LC_CTYPE category for the ``german'' locale would be found in /usr/lib/locale/german/LC_CTYPE.

A value of ``C'' for locale specifies the default environment.

A value of ``""'' for locale specifies that the locale should be taken from environment variables. For each of the above categories (not LC_ALL), the first of three environment variables with a nonempty value is used: LC_ALL, the category's name (e.g., LC_CTYPE), and LANG.

At program startup, the equivalent of

   setlocale(LC_ALL, "C")

is executed. This has the effect of initializing each category to the locale described by the locale ``C.''

If a pointer to a string is given for locale, setlocale attempts to set the locale for the given category to locale. If setlocale succeeds, the description of the new locale is returned. If setlocale fails, a null pointer is returned and the program's locale is not changed.

For category LC_ALL, the behavior is slightly different. If a pointer to a string is given for locale and LC_ALL is given for category, setlocale attempts to set the locale for all the categories to locale. The locale may be a simple locale, consisting of a single locale, or a composite locale. A composite locale is a string returned by a previous call to setlocale with LC_ALL for which the locale did not consist of identical category values. If setlocale fails to set the locale for any category, a null pointer is returned and the program's locale for all categories is not changed. Otherwise, a description of the new locale is returned.

A null pointer for locale causes setlocale to return the current locale associated with the category. The program's locale is not changed.

Security considerations

For processes that have gained privilege, locale data files without general read permission will not be accepted by the localization code. This prevents malicious users from gaining access to protected system files through internationalized system routines.

Files


/usr/lib/locale/C/LC_CTYPE
LC_CTYPE database for the C locale

/usr/lib/locale/C/LC_NUMERIC
LC_NUMERIC database for the C locale

/usr/lib/locale/C/LC_TIME
LC_TIME database for the C locale

/usr/lib/locale/C/LC_COLLATE
LC_COLLATE database for the C locale

/usr/lib/locale/C/LC_MESSAGES
LC_MESSAGES database for the C locale

/usr/lib/locale/C/LC_MONETARY
LC_MONETARY database for the C locale

/usr/lib/locale/locale/category
files containing the locale-specific information for each locale and category

References

catgets(3C), catopen(3C), ctime(3C), ctype(3C), environ(5), fprintf(3S), getdate(3C), gettxt(3C), localeconv(3C), mbchar(3C), mbstring(3C), strcoll(3C), strftime(3C), strtod(3C), strxfrm(3C)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004