1SETLOCALE(3) Linux Programmer's Manual SETLOCALE(3)
2
3
4
6 setlocale - set the current locale
7
9 #include <locale.h>
10
11 char *setlocale(int category, const char *locale);
12
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
24 geography-related items (*)
25 LC_COLLATE String collation
26 LC_CTYPE Character classification
27 LC_IDENTIFICATION Metadata describing the locale (*)
28 LC_MEASUREMENT Settings related to measurements
29 (metric versus US 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
39 extensions. For further information on these locale categories, see
40 locale(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 cate‐
50 gory), the environment variable LC_ALL is inspected, next the environ‐
51 ment variable with the same name as the category (see the table above),
52 and finally the environment variable LANG. The first existing environ‐
53 ment variable is used. If its value is not a valid locale specifica‐
54 tion, 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
63 locales, 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, by using the values returned from a
73 localeconv(3) call for locale-dependent information, by using the
74 multibyte and wide character functions for text processing if
75 MB_CUR_MAX > 1, and by using strcoll(3), wcscoll(3) or strxfrm(3),
76 wcsxfrm(3) to compare strings.
77
79 A successful call to setlocale() returns an opaque string that corre‐
80 sponds to the locale set. This string may be allocated in static stor‐
81 age. The string returned is such that a subsequent call with that
82 string and its associated category will restore that part of the
83 process's locale. The return value is NULL if the request cannot be
84 honored.
85
87 For an explanation of the terms used in this section, see
88 attributes(7).
89
90 ┌────────────┬───────────────┬────────────────────────────┐
91 │Interface │ Attribute │ Value │
92 ├────────────┼───────────────┼────────────────────────────┤
93 │setlocale() │ Thread safety │ MT-Unsafe const:locale env │
94 └────────────┴───────────────┴────────────────────────────┘
95
97 POSIX.1-2001, POSIX.1-2008, C89, C99.
98
99 The C standards specify only the categories LC_ALL, LC_COLLATE,
100 LC_CTYPE, LC_MONETARY, LC_NUMERIC, and LC_TIME. POSIX.1 adds LC_MES‐
101 SAGES. The remaining categories are GNU extensions.
102
104 locale(1), localedef(1), isalpha(3), localeconv(3), nl_langinfo(3),
105 rpmatch(3), strcoll(3), strftime(3), charsets(7), locale(7)
106
108 This page is part of release 5.04 of the Linux man-pages project. A
109 description of the project, information about reporting bugs, and the
110 latest version of this page, can be found at
111 https://www.kernel.org/doc/man-pages/.
112
113
114
115GNU 2017-09-15 SETLOCALE(3)