1 .\" Copyright (C) 2014 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH DUPLOCALE 3 2021-03-22 "Linux" "Linux Programmer's Manual"
27 duplocale \- duplicate a locale object
30 .B #include <locale.h>
32 .BI "locale_t duplocale(locale_t " locobj );
36 Feature Test Macro Requirements for glibc (see
37 .BR feature_test_macros (7)):
50 function creates a duplicate of the locale object referred to by
56 .BR LC_GLOBAL_LOCALE ,
58 creates a locale object containing a copy of the global locale
64 returns a handle for the new locale object.
69 to indicate the error.
73 Insufficient memory to create the duplicate locale object.
77 function first appeared in version 2.3 of the GNU C library.
81 Duplicating a locale can serve the following purposes:
83 To create a copy of a locale object in which one of more categories
84 are to be modified (using
87 To obtain a handle for the current locale which can used in
88 other functions that employ a locale handle, such as
90 This is done by applying
92 to the value returned by the following call:
94 loc = uselocale((locale_t) 0);
96 This technique is necessary, because the above
98 call may return the value
99 .BR LC_GLOBAL_LOCALE ,
100 which results in undefined behavior if passed to functions such as
104 can be used to ensure that the
106 value is converted into a usable locale object.
109 Each locale object created by
111 should be deallocated using
114 The program below uses
118 to obtain a handle for the current locale which is then passed to
120 The program takes one command-line argument,
121 a string of characters that is converted to uppercase and
122 displayed on standard output.
123 An example of its use is the following:
134 #define _XOPEN_SOURCE 700
140 #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
144 main(int argc, char *argv[])
149 fprintf(stderr, "Usage: %s string\en", argv[0]);
153 /* This sequence is necessary, because uselocale() might return
154 the value LC_GLOBAL_LOCALE, which can\(aqt be passed as an
155 argument to toupper_l(). */
157 loc = uselocale((locale_t) 0);
158 if (loc == (locale_t) 0)
159 errExit("uselocale");
161 nloc = duplocale(loc);
162 if (nloc == (locale_t) 0)
163 errExit("duplocale");
165 for (char *p = argv[1]; *p; p++)
166 putchar(toupper_l(*p, nloc));