]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/setlocale.3
c793b0d64b019c5228ed846a38eaaaf0a7de1255
[thirdparty/man-pages.git] / man3 / setlocale.3
1 .\" (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\" and 1999 by Bruno Haible (haible@clisp.cons.org)
3 .\"
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" License.
24 .\" Modified Sat Jul 24 18:20:12 1993 by Rik Faith (faith@cs.unc.edu)
25 .\" Modified Tue Jul 15 16:49:10 1997 by Andries Brouwer (aeb@cwi.nl)
26 .\" Modified Sun Jul 4 14:52:16 1999 by Bruno Haible (haible@clisp.cons.org)
27 .\" Modified Tue Aug 24 17:11:01 1999 by Andries Brouwer (aeb@cwi.nl)
28 .\" Modified Tue Feb 6 03:31:55 2001 by Andries Brouwer (aeb@cwi.nl)
29 .\"
30 .TH SETLOCALE 3 1999-07-04 "GNU" "Linux Programmer's Manual"
31 .SH NAME
32 setlocale \- set the current locale
33 .SH SYNOPSIS
34 .nf
35 .B #include <locale.h>
36 .sp
37 .BI "char *setlocale(int " category ", const char *" locale );
38 .fi
39 .SH DESCRIPTION
40 The
41 .BR setlocale ()
42 function is used to set or query the program's current locale.
43 .PP
44 If
45 .I locale
46 is not NULL,
47 the program's current locale is modified according to the arguments.
48 The argument
49 .I category
50 determines which parts of the program's current locale should be modified.
51 .TP
52 .B LC_ALL
53 for all of the locale.
54 .TP
55 .B LC_COLLATE
56 for regular expression matching (it determines the meaning
57 of range expressions and equivalence classes) and string collation.
58 .TP
59 .B LC_CTYPE
60 for regular expression matching, character classification, conversion,
61 case-sensitive comparison, and wide character functions.
62 .TP
63 .B LC_MESSAGES
64 for localizable natural-language messages.
65 .TP
66 .B LC_MONETARY
67 for monetary formatting.
68 .TP
69 .B LC_NUMERIC
70 for number formatting (such as the decimal point and the thousands separator).
71 .TP
72 .B LC_TIME
73 for time and date formatting.
74 .PP
75 The argument
76 .I locale
77 is a pointer to a character string containing the
78 required setting of
79 .IR category .
80 Such a string is either a well-known constant like "C" or "da_DK"
81 (see below), or an opaque string that was returned by another call of
82 .BR setlocale ().
83 .PP
84 If
85 .I locale
86 is
87 .BR """""" ,
88 each part of the locale that should be modified is set according to the
89 environment variables.
90 The details are implementation dependent.
91 For glibc, first
92 .\" [This is false on my system - must check which library versions do this]
93 .\" if
94 .\" .I category
95 .\" is LC_MESSAGES, the environment variable LANGUAGE is inspected,
96 .\" then
97 (regardless of
98 .IR category ),
99 the environment variable
100 .B LC_ALL
101 is inspected,
102 next the environment variable with the same name as the category
103 .RM ( LC_COLLATE ,
104 .BR LC_CTYPE ,
105 .BR LC_MESSAGES ,
106 .BR LC_MONETARY ,
107 .BR LC_NUMERIC ,
108 .BR LC_TIME )
109 and finally the environment variable
110 .BR LANG .
111 The first existing environment variable is used.
112 If its value is not a valid locale specification, the locale
113 is unchanged, and
114 .BR setlocale ()
115 returns NULL.
116 .\" The environment variable LANGUAGE may contain several, colon-separated,
117 .\" locale names.
118 .PP
119 The locale
120 .B """C"""
121 or
122 .B """POSIX"""
123 is a portable locale; its
124 .BR LC_CTYPE
125 part corresponds to the 7-bit ASCII
126 character set.
127 .PP
128 A locale name is typically of the form
129 .IR language "[_" territory "][." codeset "][@" modifier "],"
130 where
131 .I language
132 is an ISO 639 language code,
133 .I territory
134 is an ISO 3166 country code, and
135 .I codeset
136 is a character set or encoding identifier like
137 .B "ISO-8859-1"
138 or
139 .BR "UTF-8" .
140 For a list of all supported locales, try "locale \-a", cf.\&
141 .BR locale (1).
142 .PP
143 If
144 .I locale
145 is NULL, the current locale is only queried, not modified.
146 .PP
147 On startup of the main program, the portable
148 .B """C"""
149 locale is selected as default.
150 A program may be made portable to all locales by calling
151 .B setlocale(LC_ALL, """""")
152 after program initialization, by using the values returned
153 from a
154 .BR localeconv (3)
155 call
156 for locale-dependent information, by using the multi-byte and wide
157 character functions for text processing if
158 .BR "MB_CUR_MAX > 1" ,
159 and by using
160 .BR strcoll (3) ,
161 .BR wcscoll (3)
162 or
163 .BR strxfrm (3),
164 .BR wcsxfrm (3)
165 to compare strings.
166 .SH "RETURN VALUE"
167 A successful call to
168 .BR setlocale ()
169 returns an opaque string that corresponds to the locale set.
170 This string may be allocated in static storage.
171 The string returned is such that a subsequent call with that string
172 and its associated category will restore that part of the process's
173 locale.
174 The return value is NULL if the request cannot be honored.
175 .SH "CONFORMING TO"
176 C89, C99, POSIX.1-2001.
177 .SH NOTES
178 Linux (that is, GNU libc) supports the portable locales
179 .BR """C""" " and " """POSIX""" .
180 In the good old days there used to be support for
181 the European Latin-1
182 .B """ISO-8859-1"""
183 locale (e.g., in libc-4.5.21 and libc-4.6.27), and the Russian
184 .B """KOI-8"""
185 (more precisely, "koi-8r") locale (e.g., in libc-4.6.27),
186 so that having an environment variable \fILC_CTYPE=ISO-8859-1\fP
187 sufficed to make
188 .BR isprint (3)
189 return the right answer.
190 These days non-English speaking Europeans have to work a bit harder,
191 and must install actual locale files.
192 .SH "SEE ALSO"
193 .BR locale (1),
194 .BR localedef (1),
195 .BR isalpha (3),
196 .BR localeconv (3),
197 .BR nl_langinfo (3),
198 .BR rpmatch (3),
199 .BR strcoll (3),
200 .BR strftime (3),
201 .BR charsets (7),
202 .BR locale (7)