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 LC_ALL for all of the locale.
22
23 LC_COLLATE
24 for regular expression matching (it determines the meaning of
25 range expressions and equivalence classes) and string collation.
26
27 LC_CTYPE
28 for regular expression matching, character classification, con‐
29 version, case-sensitive comparison, and wide character func‐
30 tions.
31
32 LC_MESSAGES
33 for localizable natural-language messages.
34
35 LC_MONETARY
36 for monetary formatting.
37
38 LC_NUMERIC
39 for number formatting (such as the decimal point and the thou‐
40 sands separator).
41
42 LC_TIME
43 for time and date formatting.
44
45 The argument locale is a pointer to a character string containing the
46 required setting of category. Such a string is either a well-known
47 constant like "C" or "da_DK" (see below), or an opaque string that was
48 returned by another call of setlocale().
49
50 If locale is "", each part of the locale that should be modified is set
51 according to the environment variables. The details are implementation
52 dependent. For glibc, first (regardless of category), the environment
53 variable LC_ALL is inspected, next the environment variable with the
54 same name as the category (LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONE‐
55 TARY, LC_NUMERIC, LC_TIME) and finally the environment variable LANG.
56 The first existing environment variable is used. If its value is not a
57 valid locale specification, the locale is unchanged, and setlocale()
58 returns NULL.
59
60 The locale "C" or "POSIX" is a portable locale; its LC_CTYPE part cor‐
61 responds to the 7-bit ASCII character set.
62
63 A locale name is typically of the form language[_territory][.code‐
64 set][@modifier], where language is an ISO 639 language code, territory
65 is an ISO 3166 country code, and codeset is a character set or encoding
66 identifier like ISO-8859-1 or UTF-8. For a list of all supported
67 locales, try "locale -a", cf. locale(1).
68
69 If locale is NULL, the current locale is only queried, not modified.
70
71 On startup of the main program, the portable "C" locale is selected as
72 default. A program may be made portable to all locales by calling set‐
73 locale(LC_ALL, "" ) after program initialization, by using the values
74 returned from a localeconv() call for locale-dependent information, by
75 using the multi-byte and wide character functions for text processing
76 if MB_CUR_MAX > 1, and by using strcoll(), wcscoll() or strxfrm(),
77 wcsxfrm() to compare strings.
78
80 A successful call to setlocale() returns an opaque string that corre‐
81 sponds to the locale set. This string may be allocated in static stor‐
82 age. The string returned is such that a subsequent call with that
83 string and its associated category will restore that part of the
84 process's locale. The return value is NULL if the request cannot be
85 honored.
86
88 C89, C99, POSIX.1-2001.
89
91 Linux (that is, GNU libc) supports the portable locales "C" and
92 "POSIX". In the good old days there used to be support for the Euro‐
93 pean Latin-1 "ISO-8859-1" locale (e.g. in libc-4.5.21 and libc-4.6.27),
94 and the Russian "KOI-8" (more precisely, "koi-8r") locale (e.g. in
95 libc-4.6.27), so that having an environment variable
96 LC_CTYPE=ISO-8859-1 sufficed to make isprint() return the right answer.
97 These days non-English speaking Europeans have to work a bit harder,
98 and must install actual locale files.
99
101 locale(1), localedef(1), isalpha(3), localeconv(3), nl_langinfo(3),
102 rpmatch(3), strcoll(3), strftime(3), charsets(4), locale(7)
103
104
105
106GNU 1999-07-04 SETLOCALE(3)