OSDN Git Service

LDP: Update original to LDP v3.68
[linuxjm/LDP_man-pages.git] / original / man3 / setlocale.3
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\" and Copyright 1999 by Bruno Haible (haible@clisp.cons.org)
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
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.
13 .\"
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.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
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 .\"
32 .TH SETLOCALE 3  2014-05-28 "GNU" "Linux Programmer's Manual"
33 .SH NAME
34 setlocale \- set the current locale
35 .SH SYNOPSIS
36 .nf
37 .B #include <locale.h>
38 .sp
39 .BI "char *setlocale(int " category ", const char *" locale );
40 .fi
41 .SH DESCRIPTION
42 The
43 .BR setlocale ()
44 function is used to set or query the program's current locale.
45 .PP
46 If
47 .I locale
48 is not NULL,
49 the program's current locale is modified according to the arguments.
50 The argument
51 .I category
52 determines which parts of the program's current locale should be modified.
53 .TS
54 lB lB
55 lB l.
56 Category        Governs
57 LC_ALL  All of the locale
58 LC_ADDRESS      T{
59 Formatting of addresses and
60 .br
61 geography-related items (*)
62 T}
63 LC_COLLATE      String collation
64 LC_CTYPE        Character classification
65 LC_IDENTIFICATION       Metadata describing the locale (*)
66 LC_MEASUREMENT  T{
67 Settings related to measurements
68 .br
69 (metric versus US customary) (*)
70 T}
71 LC_MESSAGES     Localizable natural-language messages
72 LC_MONETARY     Formatting of monetary values
73 LC_NAME Formatting of salutations for persons (*)
74 LC_NUMERIC      Formatting of nonmonetary numeric values
75 LC_PAPER        Settings related to the standard paper size (*)
76 LC_TELEPHONE    Formats to be used with telephone services (*)
77 LC_TIME Formatting of date and time values
78 .TE
79 .PP
80 The categories marked with an asterisk in the above table
81 are GNU extensions.
82 For further information on these locale categories, see
83 .BR locale (7).
84 .PP
85 The argument
86 .I locale
87 is a pointer to a character string containing the
88 required setting of
89 .IR category .
90 Such 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
92 .BR setlocale ().
93 .PP
94 If
95 .I locale
96 is an empty string,
97 .BR """""" ,
98 each part of the locale that should be modified is set according to the
99 environment variables.
100 The details are implementation-dependent.
101 For glibc, first (regardless of
102 .IR category ),
103 the environment variable
104 .B LC_ALL
105 is inspected,
106 next the environment variable with the same name as the category
107 (see the table above),
108 and finally the environment variable
109 .BR LANG .
110 The first existing environment variable is used.
111 If its value is not a valid locale specification, the locale
112 is unchanged, and
113 .BR setlocale ()
114 returns NULL.
115 .PP
116 The locale
117 .B """C"""
118 or
119 .B """POSIX"""
120 is a portable locale; its
121 .B LC_CTYPE
122 part corresponds to the 7-bit ASCII
123 character set.
124 .PP
125 A locale name is typically of the form
126 .IR language "[_" territory "][." codeset "][@" modifier "],"
127 where
128 .I language
129 is an ISO 639 language code,
130 .I territory
131 is an ISO 3166 country code, and
132 .I codeset
133 is a character set or encoding identifier like
134 .B "ISO-8859-1"
135 or
136 .BR "UTF-8" .
137 For a list of all supported locales, try "locale \-a", cf.\&
138 .BR locale (1).
139 .PP
140 If
141 .I locale
142 is NULL, the current locale is only queried, not modified.
143 .PP
144 On startup of the main program, the portable
145 .B """C"""
146 locale is selected as default.
147 A program may be made portable to all locales by calling:
148 .nf
149
150     setlocale(LC_ALL, "");
151
152 .fi
153 after program initialization, by using the values returned
154 from a
155 .BR localeconv (3)
156 call
157 for locale-dependent information, by using the multibyte and wide
158 character functions for text processing if
159 .BR "MB_CUR_MAX > 1" ,
160 and by using
161 .BR strcoll (3),
162 .BR wcscoll (3)
163 or
164 .BR strxfrm (3),
165 .BR wcsxfrm (3)
166 to compare strings.
167 .SH RETURN VALUE
168 A successful call to
169 .BR setlocale ()
170 returns an opaque string that corresponds to the locale set.
171 This string may be allocated in static storage.
172 The string returned is such that a subsequent call with that string
173 and its associated category will restore that part of the process's
174 locale.
175 The return value is NULL if the request cannot be honored.
176 .SH CONFORMING TO
177 C89, C99, POSIX.1-2001.
178 .SH SEE ALSO
179 .BR locale (1),
180 .BR localedef (1),
181 .BR isalpha (3),
182 .BR localeconv (3),
183 .BR nl_langinfo (3),
184 .BR rpmatch (3),
185 .BR strcoll (3),
186 .BR strftime (3),
187 .BR charsets (7),
188 .BR locale (7)
189 .SH COLOPHON
190 This page is part of release 3.68 of the Linux
191 .I man-pages
192 project.
193 A description of the project,
194 information about reporting bugs,
195 and the latest version of this page,
196 can be found at
197 \%http://www.kernel.org/doc/man\-pages/.