1NEWLOCALE(3P) POSIX Programmer's Manual NEWLOCALE(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 newlocale — create or modify a locale object
13
15 #include <locale.h>
16
17 locale_t newlocale(int category_mask, const char *locale,
18 locale_t base);
19
21 The newlocale() function shall create a new locale object or modify an
22 existing one. If the base argument is (locale_t)0, a new locale object
23 shall be created. It is unspecified whether the locale object pointed
24 to by base shall be modified, or freed and a new locale object created.
25
26 The category_mask argument specifies the locale categories to be set or
27 modified. Values for category_mask shall be constructed by a bitwise-
28 inclusive OR of the symbolic constants LC_CTYPE_MASK, LC_NUMERIC_MASK,
29 LC_TIME_MASK, LC_COLLATE_MASK, LC_MONETARY_MASK, and LC_MESSAGES_MASK,
30 or any of the implementation-defined mask values defined in <locale.h>.
31
32 For each category with the corresponding bit set in category_mask the
33 data from the locale named by locale shall be used. In the case of mod‐
34 ifying an existing locale object, the data from the locale named by
35 locale shall replace the existing data within the locale object. If a
36 completely new locale object is created, the data for all sections not
37 requested by category_mask shall be taken from the default locale.
38
39 The following preset values of locale are defined for all settings of
40 category_mask:
41
42 "POSIX" Specifies the minimal environment for C-language transla‐
43 tion called the POSIX locale.
44
45 "C" Equivalent to "POSIX".
46
47 "" Specifies an implementation-defined native environment.
48 This corresponds to the value of the associated environment
49 variables, LC_* and LANG; see the Base Definitions volume
50 of POSIX.1‐2017, Chapter 7, Locale and Chapter 8, Environ‐
51 ment Variables.
52
53 If the base argument is not (locale_t)0 and the newlocale() function
54 call succeeds, the contents of base are unspecified. Applications shall
55 ensure that they stop using base as a locale object before calling
56 newlocale(). If the function call fails and the base argument is not
57 (locale_t)0, the contents of base shall remain valid and unchanged.
58
59 The behavior is undefined if the base argument is the special locale
60 object LC_GLOBAL_LOCALE, or is not a valid locale object handle and is
61 not (locale_t)0.
62
64 Upon successful completion, the newlocale() function shall return a
65 handle which the caller may use on subsequent calls to duplocale(),
66 freelocale(), and other functions taking a locale_t argument.
67
68 Upon failure, the newlocale() function shall return (locale_t)0 and set
69 errno to indicate the error.
70
72 The newlocale() function shall fail if:
73
74 ENOMEM There is not enough memory available to create the locale object
75 or load the locale data.
76
77 EINVAL The category_mask contains a bit that does not correspond to a
78 valid category.
79
80 ENOENT For any of the categories in category_mask, the locale data is
81 not available.
82
83 The newlocale() function may fail if:
84
85 EINVAL The locale argument is not a valid string pointer.
86
87 The following sections are informative.
88
90 Constructing a Locale Object from Different Locales
91 The following example shows the construction of a locale where the
92 LC_CTYPE category data comes from a locale loc1 and the LC_TIME cate‐
93 gory data from a locale loc2:
94
95
96 #include <locale.h>
97 ...
98 locale_t loc, new_loc;
99
100 /* Get the "loc1" data. */
101
102 loc = newlocale (LC_CTYPE_MASK, "loc1", (locale_t)0);
103 if (loc == (locale_t) 0)
104 abort ();
105
106 /* Get the "loc2" data. */
107
108 new_loc = newlocale (LC_TIME_MASK, "loc2", loc);
109 if (new_loc != (locale_t) 0)
110 /* We don t abort if this fails. In this case this
111 simply used to unchanged locale object. */
112 loc = new_loc;
113
114 ...
115
116 Freeing up a Locale Object
117 The following example shows a code fragment to free a locale object
118 created by newlocale():
119
120
121 #include <locale.h>
122 ...
123
124 /* Every locale object allocated with newlocale() should be
125 * freed using freelocale():
126 */
127
128 locale_t loc;
129
130 /* Get the locale. */
131
132 loc = newlocale (LC_CTYPE_MASK | LC_TIME_MASK, "locname", (locale_t)0);
133
134 /* ... Use the locale object ... */
135 ...
136
137 /* Free the locale object resources. */
138 freelocale (loc);
139
141 Handles for locale objects created by the newlocale() function should
142 either be released by a corresponding call to freelocale(), or be used
143 as a base locale to another newlocale() call.
144
145 The special locale object LC_GLOBAL_LOCALE must not be passed for the
146 base argument, even when returned by the uselocale() function.
147
149 None.
150
152 None.
153
155 duplocale(), freelocale(), uselocale()
156
157 The Base Definitions volume of POSIX.1‐2017, Chapter 7, Locale, Chapter
158 8, Environment Variables, <locale.h>
159
161 Portions of this text are reprinted and reproduced in electronic form
162 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
163 table Operating System Interface (POSIX), The Open Group Base Specifi‐
164 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
165 Electrical and Electronics Engineers, Inc and The Open Group. In the
166 event of any discrepancy between this version and the original IEEE and
167 The Open Group Standard, the original IEEE and The Open Group Standard
168 is the referee document. The original Standard can be obtained online
169 at http://www.opengroup.org/unix/online.html .
170
171 Any typographical or formatting errors that appear in this page are
172 most likely to have been introduced during the conversion of the source
173 files to man page format. To report such errors, see https://www.ker‐
174 nel.org/doc/man-pages/reporting_bugs.html .
175
176
177
178IEEE/The Open Group 2017 NEWLOCALE(3P)