1DUPLOCALE(3P)              POSIX Programmer's Manual             DUPLOCALE(3P)
2
3
4

PROLOG

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

NAME

12       duplocale — duplicate a locale object
13

SYNOPSIS

15       #include <locale.h>
16
17       locale_t duplocale(locale_t locobj);
18

DESCRIPTION

20       The duplocale() function shall create a duplicate copy  of  the  locale
21       object referenced by the locobj argument.
22
23       If  the locobj argument is LC_GLOBAL_LOCALE, duplocale() shall create a
24       new locale object containing a copy of the global locale determined  by
25       the setlocale() function.
26
27       The  behavior is undefined if the locobj argument is not a valid locale
28       object handle.
29

RETURN VALUE

31       Upon successful completion, the duplocale()  function  shall  return  a
32       handle  for  a  new  locale object. Otherwise, duplocale() shall return
33       (locale_t)0 and set errno to indicate the error.
34

ERRORS

36       The duplocale() function shall fail if:
37
38       ENOMEM There is not enough memory available to create the locale object
39              or load the locale data.
40
41       The following sections are informative.
42

EXAMPLES

44   Constructing an Altered Version of an Existing Locale Object
45       The  following  example  shows  a  code  fragment  to create a slightly
46       altered version of an existing locale  object.  The  function  takes  a
47       locale  object  and  a locale name and it replaces the LC_TIME category
48       data in the locale object with that from the named locale.
49
50
51           #include <locale.h>
52           ...
53
54           locale_t
55           with_changed_lc_time (locale_t obj, const char *name)
56           {
57
58               locale_t retval = duplocale (obj);
59               if (retval != (locale_t) 0)
60               {
61                   locale_t changed = newlocale (LC_TIME_MASK, name, retval);
62                   if (changed == (locale_t) 0)
63                       /* An error occurred. Free all allocated resources. */
64                       freelocale (retval);
65                   retval = changed;
66               }
67               return retval;
68           }
69

APPLICATION USAGE

71       The use of the duplocale() function is recommended for situations where
72       a  locale  object  is being used in multiple places, and it is possible
73       that the lifetime of the locale object might end before  all  uses  are
74       finished.  Another reason to duplicate a locale object is if a slightly
75       modified form is needed.  This can be achieved by a call to newlocale()
76       following the duplocale() call.
77
78       As with the newlocale() function, handles for locale objects created by
79       the duplocale() function should be released by a corresponding call  to
80       freelocale().
81
82       The  duplocale()  function  can also be used in conjunction with uselo‐
83       cale((locale_t)0).  This returns the locale in effect for  the  calling
84       thread,    but   can   have   the   value   LC_GLOBAL_LOCALE.   Passing
85       LC_GLOBAL_LOCALE to functions such as isalnum_l() results in  undefined
86       behavior,  but  applications can convert it into a usable locale object
87       by using duplocale().
88

RATIONALE

90       None.
91

FUTURE DIRECTIONS

93       None.
94

SEE ALSO

96       freelocale(), newlocale(), uselocale()
97
98       The Base Definitions volume of POSIX.1‐2017, <locale.h>
99
101       Portions of this text are reprinted and reproduced in  electronic  form
102       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
103       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
104       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
105       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
106       event of any discrepancy between this version and the original IEEE and
107       The Open Group Standard, the original IEEE and The Open Group  Standard
108       is  the  referee document. The original Standard can be obtained online
109       at http://www.opengroup.org/unix/online.html .
110
111       Any typographical or formatting errors that appear  in  this  page  are
112       most likely to have been introduced during the conversion of the source
113       files to man page format. To report such errors,  see  https://www.ker
114       nel.org/doc/man-pages/reporting_bugs.html .
115
116
117
118IEEE/The Open Group                  2017                        DUPLOCALE(3P)
Impressum