SETLOCALE(3) | Library Functions Manual | SETLOCALE(3) |
setlocale
—
natural language formatting for C
Standard C Library (libc, -lc)
#include
<locale.h>
char *
setlocale
(int category,
const char *locale);
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
LC_COLLATE
strcoll
()
and
strxfrm
().LC_CTYPE
LC_MESSAGES
LC_MONETARY
localeconv
()
function.LC_NUMERIC
printf
()
and
scanf
(),
as well as values returned by localeconv
().LC_TIME
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.
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.
No errors are defined.
colldef(1), mklocale(1), catopen(3), ctype(3), localeconv(3), multibyte(3), strcoll(3), strxfrm(3), euc(5), utf8(5), environ(7)
The setlocale
() function conforms to
ISO/IEC 9899:1999
(“ISO C99”).
The setlocale
() function first appeared in
4.4BSD.
November 21, 2003 | macOS 15.0 |