DUPLOCALE(3P)
๐ DUPLOCALE ๐
okay bestie, welcome to the POSIX Programmer's Manual โจ this page is duplocale from DUPLOCALE(3P), and yes it's the IEEE/The Open Group one. heads up tho: the Linux implementation of this interface may differ, so if you're on Linux, go peek at the corresponding Linux manual page for the actual tea โ. also possible it's justโฆ not implemented on Linux at all. vibe check accordingly. ๐ซถ
โจ NAME โจ
duplocale โ duplicate a locale object ๐
๐ธ SYNOPSIS ๐ธ
#include <locale.h>
locale_t duplocale(locale_t locobj);
๐ฆ DESCRIPTION ๐ฆ
so what does she do? the duplocale() function shall create a duplicate copy of the locale object referenced by the locobj argument. that's it, that's the whole job. iconic. ๐
if locobj is LC_GLOBAL_LOCALE, then duplocale() shall create a new locale object containing a copy of the global locale determined by the setlocale() function. yes girl, it knows what you mean.
๐ BUT โ the behavior is undefined if locobj is not a valid locale object handle. not "undefined" as in "teehee whatever", undefined as in the standard will simply not be responsible for what happens next. do not do this. periodt.
โญ RETURN VALUE โญ
upon successful completion, duplocale() shall return a handle for a new locale object ๐
otherwise? she returns (locale_t)0 and sets errno to indicate the error. so always check, bestie. always check. ๐ญ
๐ ERRORS ๐
the duplocale() function shall fail if:
ENOMEMโ there is not enough memory available to create the locale object or load the locale data. the audacity honestly.
the following sections are informative. (yes, that's what the original says, and we respect the original's little announcements ๐)
๐ EXAMPLES ๐
๐ซ Constructing an Altered Version of an Existing Locale Object ๐ซ
okay so here's the slay: this example shows a code fragment that creates a slightly altered version of an existing locale object. the function takes a locale object and a locale name, and it replaces the LC_TIME category data in the locale object with that from the named locale. main character behavior, fr fr โจ
#include <locale.h>
...
locale_t
with_changed_lc_time (locale_t obj, const char *name)
{
locale_t retval = duplocale (obj);
if (retval != (locale_t) 0)
{
locale_t changed = newlocale (LC_TIME_MASK, name, retval);
if (changed == (locale_t) 0)
/* An error occurred. Free all allocated resources. */
freelocale (retval);
retval = changed;
}
return retval;
}
๐ APPLICATION USAGE ๐
ngl, the use of duplocale() is recommended for situations where a locale object is being used in multiple places, and it's possible that the lifetime of the locale object might end before all uses are finished. like, the object could just โจleave the chatโจ mid-use and that's a whole problem.
another reason to duplicate a locale object is if a slightly modified form is needed โ and you get that by calling newlocale() after the duplocale() call. combo move. ๐ซถ
also, same energy as with the newlocale() function: handles for locale objects created by duplocale() should be released by a corresponding call to freelocale(). clean up after yourself, queen ๐
and here's a cute trick โ duplocale() can also be used in conjunction with uselocale((locale_t)0). that returns the locale in effect for the calling thread, but it can have the value LC_GLOBAL_LOCALE. passing LC_GLOBAL_LOCALE to functions such as isalnum_l() results in undefined behavior ๐จ โ but applications can convert it into a usable locale object by using duplocale(). see? she's useful. she's that girl.
๐ง RATIONALE ๐ง
None. (not a single thought, head empty, no notes ๐)
๐ฎ FUTURE DIRECTIONS ๐ฎ
None. (same energy, honestly ๐)
๐ SEE ALSO ๐
freelocale()newlocale()uselocale()
The Base Definitions volume of POSIX.1โ2017, <locale.h> ๐
๐ COPYRIGHT ๐
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. ๐
in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie!! ๐ธ this diva was brought to you by IEEE/The Open Group, 2017, living her best life as DUPLOCALE(3P) โจ go duplicate something responsibly, and don't forget your freelocale() ๐ซถ๐๐
๐ฆ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 ยท custom
- alpine 3.23: man-pages-posix 2017a-r0 ยท custom
- alpine 3.24: man-pages-posix 2017a-r0 ยท custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 ยท SUSE-IEEE
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms