1SETLOCALE(3)               Linux Programmer's Manual              SETLOCALE(3)
2
3
4

NAME

6       setlocale - set the current locale
7

SYNOPSIS

9       #include <locale.h>
10
11       char *setlocale(int category, const char *locale);
12

DESCRIPTION

14       The  setlocale() function is used to set or query the program's current
15       locale.
16
17       If locale is not NULL, the program's current locale is modified accord‐
18       ing  to the arguments.  The argument category determines which parts of
19       the program's current locale should be modified.
20
21       Category            Governs
22       LC_ALL              All of the locale
23       LC_ADDRESS          Formatting of addresses and geography-related items
24                           (*)
25       LC_COLLATE          String collation
26       LC_CTYPE            Character classification
27       LC_IDENTIFICATION   Metadata describing the locale (*)
28       LC_MEASUREMENT      Settings related to measurements (metric versus US
29                           customary) (*)
30       LC_MESSAGES         Localizable natural-language messages
31       LC_MONETARY         Formatting of monetary values
32       LC_NAME             Formatting of salutations for persons (*)
33       LC_NUMERIC          Formatting of nonmonetary numeric values
34       LC_PAPER            Settings related to the standard paper size (*)
35       LC_TELEPHONE        Formats to be used with telephone services (*)
36       LC_TIME             Formatting of date and time values
37
38       The categories marked with an asterisk in the above table are  GNU  ex‐
39       tensions.   For further information on these locale categories, see lo‐
40       cale(7).
41
42       The argument locale is a pointer to a character string  containing  the
43       required  setting  of  category.   Such a string is either a well-known
44       constant like "C" or "da_DK" (see below), or an opaque string that  was
45       returned by another call of setlocale().
46
47       If  locale  is an empty string, "", each part of the locale that should
48       be modified is set according to the environment variables.  The details
49       are  implementation-dependent.  For glibc, first (regardless of catego‐
50       ry), the environment variable LC_ALL is inspected, next the environment
51       variable  with the same name as the category (see the table above), and
52       finally the environment variable LANG.  The first existing  environment
53       variable  is  used.   If its value is not a valid locale specification,
54       the locale is unchanged, and setlocale() returns NULL.
55
56       The locale "C" or "POSIX" is a portable locale; it exists on  all  con‐
57       forming systems.
58
59       A  locale  name  is  typically  of the form language[_territory][.code‐
60       set][@modifier], where language is an ISO 639 language code,  territory
61       is an ISO 3166 country code, and codeset is a character set or encoding
62       identifier like ISO-8859-1 or UTF-8.  For a list of all  supported  lo‐
63       cales, try "locale -a" (see locale(1)).
64
65       If locale is NULL, the current locale is only queried, not modified.
66
67       On  startup of the main program, the portable "C" locale is selected as
68       default.  A program may be made portable to all locales by calling:
69
70           setlocale(LC_ALL, "");
71
72       after program initialization, and then:
73
74       • using the values returned from a localeconv(3) call for locale-depen‐
75         dent information;
76
77       • using  the multibyte and wide character functions for text processing
78         if MB_CUR_MAX > 1;
79
80       • using strcoll(3) and strxfrm(3) to compare strings; and
81
82       • using wcscoll(3) and wcsxfrm(3) to compare wide-character strings.
83

RETURN VALUE

85       A successful call to setlocale() returns an opaque string  that  corre‐
86       sponds to the locale set.  This string may be allocated in static stor‐
87       age.  The string returned is such that  a  subsequent  call  with  that
88       string  and  its  associated  category  will  restore  that part of the
89       process's locale.  The return value is NULL if the  request  cannot  be
90       honored.
91

ATTRIBUTES

93       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
94       tributes(7).
95
96       ┌─────────────────────────┬───────────────┬────────────────────────────┐
97Interface                Attribute     Value                      
98       ├─────────────────────────┼───────────────┼────────────────────────────┤
99setlocale()              │ Thread safety │ MT-Unsafe const:locale env │
100       └─────────────────────────┴───────────────┴────────────────────────────┘
101

CONFORMING TO

103       POSIX.1-2001, POSIX.1-2008, C89, C99.
104
105       The  C  standards  specify  only  the  categories  LC_ALL,  LC_COLLATE,
106       LC_CTYPE,  LC_MONETARY,  LC_NUMERIC, and LC_TIME.  POSIX.1 adds LC_MES‐
107       SAGES.  The remaining categories are GNU extensions.
108

SEE ALSO

110       locale(1), localedef(1), isalpha(3), localeconv(3), nl_langinfo(3), rp‐
111       match(3), strcoll(3), strftime(3), charsets(7), locale(7)
112

COLOPHON

114       This  page  is  part of release 5.12 of the Linux man-pages project.  A
115       description of the project, information about reporting bugs,  and  the
116       latest     version     of     this    page,    can    be    found    at
117       https://www.kernel.org/doc/man-pages/.
118
119
120
121GNU                               2021-03-22                      SETLOCALE(3)
Impressum