SETLOCALE(3) BSD Library Functions Manual SETLOCALE(3)
NAME
setlocale -- natural language formatting for C
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <locale.h>
char *
setlocale(int category, const char *locale);
DESCRIPTION
The setlocale() function sets the C library's notion of natural language formatting style for particular sets of routines. Each such style is called a `locale' and is invoked using
an appropriate name passed as a C string.
The setlocale() function recognizes several categories of routines. These are the categories and the sets of routines they select:
LC_ALL Set the entire locale generically.
LC_COLLATE Set a locale for string collation routines. This controls alphabetic ordering in strcoll() and strxfrm().
LC_CTYPE Set a locale for the ctype(3) and multibyte(3) functions. This controls recognition of upper and lower case, alphabetic or non-alphabetic characters, and so on.
LC_MESSAGES Set a locale for message catalogs, see catopen(3) function.
LC_MONETARY Set a locale for formatting monetary values; this affects the localeconv() function.
LC_NUMERIC Set a locale for formatting numbers. This controls the formatting of decimal points in input and output of floating point numbers in functions such as printf() and
scanf(), as well as values returned by localeconv().
LC_TIME Set a locale for formatting dates and times using the strftime() function.
Only three locales are defined by default: the empty string "" (which denotes the native environment) and the "C" and "POSIX" locales (which denote the C language environment). A
locale argument of NULL causes setlocale() to return the current locale. An argument of "" will determine the name of the new locale taking into account the environment variables
LANG and LC_*. If these environment variables yield a locale that is invalid, NULL will be returned and the current locale will remain unchanged. By default, C programs start in
the "C" locale. The only function in the library that sets the locale is setlocale(); the locale is never changed as a side effect of some other routine.
RETURN VALUES
Upon successful completion, setlocale() returns the string associated with the specified category for the requested locale. The setlocale() function returns NULL and fails to
change the locale if the given combination of category and locale makes no sense.
FILES
$PATH_LOCALE/locale/category
/usr/share/locale/locale/category locale file for the locale locale and the category category.
/usr/local/share/locale/locale/category
locale file for the locale locale and the category category.
NEWLOCALE(3) BSD Library Functions Manual NEWLOCALE(3)
NAME
newlocale -- Create a new locale
SYNOPSIS
#include <xlocale.h>
locale_t
newlocale(int mask, const char * locale, locale_t base);
DESCRIPTION
Creates a new locale_t based off the locale specified by base. The categories specified by mask will be replaced to correspond with the named locale.
The mask is the logical OR of the following:
LC_COLLATE_MASK Collation
LC_CTYPE_MASK Character type
LC_MESSAGES_MASK Messages
LC_MONETARY_MASK Monetary
LC_NUMERIC_MASK Numeric
LC_TIME_MASK Time
LC_ALL_MASK The logical OR of all of the above
The locale string is typically the name of one of the directories in /usr/share/locale. If locale is NULL, then the C locale is used. If locale is an empty string, then it will
look for environment variables: LC_ALL, then LC_* if the corresponding LC_*_MASK bit is set, then the LANG environment variable. If none of these are found, it will default to the C
locale.
If base is NULL, the current locale is used. If base is LC_GLOBAL_LOCALE, the global locale is used.
If mask is LC_ALL_MASK, base is ignored. In order to create a C locale_t value, use newlocale(LC_ALL_MASK, NULL, NULL).
RETURN VALUES
Returns a new locale_t, or NULL in case of error. New locales should be freed with freelocale(3).