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> ๐Ÿ“š


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