]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/setlocale.3
sched_setattr.2: Minor tweaks to Claudio Scordino's patch
[thirdparty/man-pages.git] / man3 / setlocale.3
CommitLineData
bf5a7247
MK
1.\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2.\" and Copyright 1999 by Bruno Haible (haible@clisp.cons.org)
fea681da 3.\"
93015253 4.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
5.\" Permission is granted to make and distribute verbatim copies of this
6.\" manual provided the copyright notice and this permission notice are
7.\" preserved on all copies.
8.\"
9.\" Permission is granted to copy and distribute modified versions of this
10.\" manual under the conditions for verbatim copying, provided that the
11.\" entire resulting derived work is distributed under the terms of a
12.\" permission notice identical to this one.
c13182ef 13.\"
fea681da
MK
14.\" Since the Linux kernel and libraries are constantly changing, this
15.\" manual page may be incorrect or out-of-date. The author(s) assume no
16.\" responsibility for errors or omissions, or for damages resulting from
17.\" the use of the information contained herein. The author(s) may not
18.\" have taken the same level of care in the production of this manual,
19.\" which is licensed free of charge, as they might when working
20.\" professionally.
c13182ef 21.\"
fea681da
MK
22.\" Formatted or processed versions of this manual, if unaccompanied by
23.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 24.\" %%%LICENSE_END
c08df37a 25.\"
fea681da
MK
26.\" Modified Sat Jul 24 18:20:12 1993 by Rik Faith (faith@cs.unc.edu)
27.\" Modified Tue Jul 15 16:49:10 1997 by Andries Brouwer (aeb@cwi.nl)
28.\" Modified Sun Jul 4 14:52:16 1999 by Bruno Haible (haible@clisp.cons.org)
29.\" Modified Tue Aug 24 17:11:01 1999 by Andries Brouwer (aeb@cwi.nl)
30.\" Modified Tue Feb 6 03:31:55 2001 by Andries Brouwer (aeb@cwi.nl)
31.\"
4b8c67d9 32.TH SETLOCALE 3 2017-09-15 "GNU" "Linux Programmer's Manual"
fea681da
MK
33.SH NAME
34setlocale \- set the current locale
35.SH SYNOPSIS
36.nf
37.B #include <locale.h>
68e4db0a 38.PP
fea681da
MK
39.BI "char *setlocale(int " category ", const char *" locale );
40.fi
41.SH DESCRIPTION
c13182ef 42The
63aa9df0 43.BR setlocale ()
fea681da
MK
44function is used to set or query the program's current locale.
45.PP
46If
47.I locale
8478ee02 48is not NULL,
fea681da
MK
49the program's current locale is modified according to the arguments.
50The argument
51.I category
52determines which parts of the program's current locale should be modified.
348aab37
MK
53.TS
54lB lB
55lB l.
56Category Governs
57LC_ALL All of the locale
58LC_ADDRESS T{
59Formatting of addresses and
60.br
61geography-related items (*)
62T}
63LC_COLLATE String collation
64LC_CTYPE Character classification
65LC_IDENTIFICATION Metadata describing the locale (*)
66LC_MEASUREMENT T{
67Settings related to measurements
68.br
69(metric versus US customary) (*)
70T}
71LC_MESSAGES Localizable natural-language messages
72LC_MONETARY Formatting of monetary values
73LC_NAME Formatting of salutations for persons (*)
74LC_NUMERIC Formatting of nonmonetary numeric values
75LC_PAPER Settings related to the standard paper size (*)
76LC_TELEPHONE Formats to be used with telephone services (*)
77LC_TIME Formatting of date and time values
78.TE
79.PP
80The categories marked with an asterisk in the above table
81are GNU extensions.
82For further information on these locale categories, see
83.BR locale (7).
fea681da
MK
84.PP
85The argument
86.I locale
87is a pointer to a character string containing the
88required setting of
89.IR category .
90Such a string is either a well-known constant like "C" or "da_DK"
91(see below), or an opaque string that was returned by another call of
e511ffb6 92.BR setlocale ().
fea681da
MK
93.PP
94If
95.I locale
e0396d76 96is an empty string,
fea681da
MK
97.BR """""" ,
98each part of the locale that should be modified is set according to the
c13182ef 99environment variables.
a43eed0c 100The details are implementation-dependent.
97aec57c 101For glibc, first (regardless of
fea681da 102.IR category ),
2f0af33b
MK
103the environment variable
104.B LC_ALL
105is inspected,
fea681da 106next the environment variable with the same name as the category
348aab37 107(see the table above),
2f0af33b
MK
108and finally the environment variable
109.BR LANG .
fea681da
MK
110The first existing environment variable is used.
111If its value is not a valid locale specification, the locale
112is unchanged, and
e511ffb6 113.BR setlocale ()
fea681da 114returns NULL.
fea681da
MK
115.PP
116The locale
117.B """C"""
118or
119.B """POSIX"""
9ce8a1e0
MM
120is a portable locale;
121it exists on all conforming systems.
fea681da
MK
122.PP
123A locale name is typically of the form
124.IR language "[_" territory "][." codeset "][@" modifier "],"
125where
126.I language
127is an ISO 639 language code,
128.I territory
129is an ISO 3166 country code, and
130.I codeset
131is a character set or encoding identifier like
132.B "ISO-8859-1"
133or
134.BR "UTF-8" .
9ab7f611
BR
135For a list of all supported locales, try "locale \-a" (see
136.BR locale (1)).
fea681da
MK
137.PP
138If
139.I locale
8478ee02 140is NULL, the current locale is only queried, not modified.
fea681da
MK
141.PP
142On startup of the main program, the portable
143.B """C"""
144locale is selected as default.
001bbe30 145A program may be made portable to all locales by calling:
408731d4
MK
146.PP
147.in +4n
148.EX
149setlocale(LC_ALL, "");
150.EE
151.in
152.PP
cfadad46 153after program initialization, by using the values returned
fea681da 154from a
fb186734 155.BR localeconv (3)
fea681da 156call
ae03dc66 157for locale-dependent information, by using the multibyte and wide
fea681da
MK
158character functions for text processing if
159.BR "MB_CUR_MAX > 1" ,
160and by using
1368e847 161.BR strcoll (3),
fb186734 162.BR wcscoll (3)
c13182ef 163or
fb186734
MK
164.BR strxfrm (3),
165.BR wcsxfrm (3)
fea681da 166to compare strings.
47297adb 167.SH RETURN VALUE
fea681da 168A successful call to
63aa9df0 169.BR setlocale ()
fea681da
MK
170returns an opaque string that corresponds to the locale set.
171This string may be allocated in static storage.
172The string returned is such that a subsequent call with that string
173and its associated category will restore that part of the process's
c13182ef 174locale.
8478ee02 175The return value is NULL if the request cannot be honored.
b3eedd06
ZL
176.SH ATTRIBUTES
177For an explanation of the terms used in this section, see
178.BR attributes (7).
179.TS
180allbox;
181lb lb lbw26
182l l l.
183Interface Attribute Value
184T{
185.BR setlocale ()
186T} Thread safety MT-Unsafe const:locale env
187.TE
847e0d88 188.sp 1
47297adb 189.SH CONFORMING TO
3a6e9ca5 190POSIX.1-2001, POSIX.1-2008, C89, C99.
2050975e
MK
191.PP
192The C standards specify only the categories
193.BR LC_ALL ,
194.BR LC_COLLATE ,
195.BR LC_CTYPE ,
196.BR LC_MONETARY ,
197.BR LC_NUMERIC ,
198and
199.BR LC_TIME .
200POSIX.1 adds
201.BR LC_MESSAGES .
202The remaining categories are GNU extensions.
47297adb 203.SH SEE ALSO
fea681da
MK
204.BR locale (1),
205.BR localedef (1),
206.BR isalpha (3),
207.BR localeconv (3),
0087e7c4 208.BR nl_langinfo (3),
aa52d776 209.BR rpmatch (3),
fea681da
MK
210.BR strcoll (3),
211.BR strftime (3),
17a1234f 212.BR charsets (7),
fea681da 213.BR locale (7)