2 .\" Copyright (C) 2014 Michael Kerrisk <mtk.manpages@gmail.com>
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.
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.
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
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH DUPLOCALE 3 2017-09-15 "Linux" "Linux Programmer's Manual"
28 duplocale \- duplicate a locale object
31 .B #include <locale.h>
33 .BI "locale_t duplocale(locale_t " locobj );
37 Feature Test Macro Requirements for glibc (see
38 .BR feature_test_macros (7)):
46 _XOPEN_SOURCE\ >=\ 700
55 function creates a duplicate of the locale object referred to by
61 .BR LC_GLOBAL_LOCALE ,
63 creates a locale object containing a copy of the global locale
69 returns a handle for the new locale object.
74 to indicate the cause of the error.
78 Insufficient memory to create the duplicate locale object.
82 function first appeared in version 2.3 of the GNU C library.
86 Duplicating a locale can serve the following purposes:
88 To create a copy of a locale object in which one of more categories
89 are to be modified (using
92 To obtain a handle for the current locale which can used in
93 other functions that employ a locale handle, such as
95 This is done by applying
97 to the value returned by the following call:
99 loc = uselocale((locale_t) 0);
101 This technique is necessary, because the above
103 call may return the value
104 .BR LC_GLOBAL_LOCALE ,
105 which results in undefined behavior if passed to functions such as
109 can be used to ensure that the
111 value is converted into a usable locale object.
114 Each locale object created by
116 should be deallocated using
119 The program below uses
123 to obtain a handle for the current locale which is then passed to
125 The program takes one command-line argument,
126 a string of characters that is converted to uppercase and
127 displayed on standard output.
128 An example of its use is the following:
139 #define _XOPEN_SOURCE 700
145 #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \\
149 main(int argc, char *argv[])
155 fprintf(stderr, "Usage: %s string\\n", argv[0]);
159 /* This sequence is necessary, because uselocale() might return
160 the value LC_GLOBAL_LOCALE, which can\(aqt be passed as an
161 argument to toupper_l() */
163 loc = uselocale((locale_t) 0);
164 if (loc == (locale_t) 0)
165 errExit("uselocale");
167 nloc = duplocale(loc);
168 if (nloc == (locale_t) 0)
169 errExit("duplocale");
171 for (p = argv[1]; *p; p++)
172 putchar(toupper_l(*p, nloc));