1 .\" Copyright (C) 2014 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH duplocale 3 (date) "Linux man-pages (unreleased)"
7 duplocale \- duplicate a locale object
10 .RI ( libc ", " \-lc )
13 .B #include <locale.h>
15 .BI "locale_t duplocale(locale_t " locobj );
19 Feature Test Macro Requirements for glibc (see
20 .BR feature_test_macros (7)):
33 function creates a duplicate of the locale object referred to by
39 .BR LC_GLOBAL_LOCALE ,
41 creates a locale object containing a copy of the global locale
47 returns a handle for the new locale object.
52 to indicate the error.
56 Insufficient memory to create the duplicate locale object.
60 function were added in glibc 2.3.
64 Duplicating a locale can serve the following purposes:
66 To create a copy of a locale object in which one of more categories
67 are to be modified (using
70 To obtain a handle for the current locale which can used in
71 other functions that employ a locale handle, such as
73 This is done by applying
75 to the value returned by the following call:
79 loc = uselocale((locale_t) 0);
83 This technique is necessary, because the above
85 call may return the value
86 .BR LC_GLOBAL_LOCALE ,
87 which results in undefined behavior if passed to functions such as
91 can be used to ensure that the
93 value is converted into a usable locale object.
96 Each locale object created by
98 should be deallocated using
101 The program below uses
105 to obtain a handle for the current locale which is then passed to
107 The program takes one command-line argument,
108 a string of characters that is converted to uppercase and
109 displayed on standard output.
110 An example of its use is the following:
120 .\" SRC BEGIN (duplocale.c)
122 #define _XOPEN_SOURCE 700
128 #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
132 main(int argc, char *argv[])
137 fprintf(stderr, "Usage: %s string\en", argv[0]);
141 /* This sequence is necessary, because uselocale() might return
142 the value LC_GLOBAL_LOCALE, which can\[aq]t be passed as an
143 argument to toupper_l(). */
145 loc = uselocale((locale_t) 0);
146 if (loc == (locale_t) 0)
147 errExit("uselocale");
149 nloc = duplocale(loc);
150 if (nloc == (locale_t) 0)
151 errExit("duplocale");
153 for (char *p = argv[1]; *p; p++)
154 putchar(toupper_l(*p, nloc));