duplocale(3)
π duplocale(3) β the glow-up button for your locales π
okay bestie, so this is the manual page for duplocale(3) from the Library Functions Manual, and it is genuinely one of my faves because it's like, tiny and powerful and it fixes a problem that would otherwise have you sobbing at 2am. π«Ά
β¨ NAME β¨
duplocale β duplicate a locale object π
π LIBRARY π
Standard C library (libc, -lc) β she's standard, she's everywhere, she's the moment. π
πΈ SYNOPSIS πΈ
#include <locale.h>
locale_t duplocale(locale_t locobj);
π§ Feature Test Macro Requirements for glibc π§
(peep feature_test_macros(7) if you wanna know more, iykyk)
duplocale():
- Since glibc 2.10:
_XOPEN_SOURCE >= 700
- Before glibc 2.10:
_GNU_SOURCE
fr fr, if you're on old glibc and nothing compiles, this is why. no cap.
π DESCRIPTION π
The duplocale() function creates a duplicate of the locale object referred to by locobj. Basically it's a photocopier but for locales. β¨
If locobj is LC_GLOBAL_LOCALE, then duplocale() creates a locale object that contains a copy of the global locale β the one determined by setlocale(3). iconic behaviour honestly. π
π₯ RETURN VALUE π₯
On success, duplocale() returns a handle for the new locale object β your shiny new baby locale. π¦
On error, it returns (locale_t) 0, and sets errno to indicate the error. sad but informative, love that for us. π
π ERRORS π
ENOMEMβ Insufficient memory to create the duplicate locale object. like, there was literally not enough room. the locale could not be born. tears.
β STANDARDS β
POSIX.1-2008.
π°οΈ HISTORY π°οΈ
glibc 2.3. she's been around. she's a legacy icon.
π NOTES π
Duplicating a locale can serve the following purposes:
- To create a copy of a locale object in which one of more categories are to be modified (using
newlocale(3)). - To obtain a handle for the current locale which can used in other functions that employ a locale handle, such as
toupper_l(3). This is done by applyingduplocale()to the value returned by the following call:
loc = uselocale((locale_t) 0);
This technique is necessary, because the above uselocale(3) call may return the value LC_GLOBAL_LOCALE, which results in undefined behavior if passed to functions such as toupper_l(3). Calling duplocale() can be used to ensure that the LC_GLOBAL_LOCALE value is converted into a usable locale object. See EXAMPLES, below. β¬οΈ
not me getting emotional about a way to safely convert LC_GLOBAL_LOCALEβ¦ but like. undefined behavior? in MY program? it's more likely than you think. π¨
Each locale object created by duplocale() should be deallocated using freelocale(3). yes bestie, you have to clean up after yourself. no leaving your locale objects lying around the group chat. π§Ή
π EXAMPLES π
The program below uses uselocale(3) and duplocale() to obtain a handle for the current locale which is then passed to toupper_l(3). The program takes one command-line argument, a string of characters that is converted to uppercase and displayed on standard output. An example of its use is the following:
$ ./a.out abc;
ABC
like, it said abc and she said ABC. ate. π
π Program source π
#define _XOPEN_SOURCE 700
#include <ctype.h>
#include <err.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
locale_t loc, nloc;
if (argc != 2) {
fprintf(stderr, "Usage: %s string\n", argv[0]);
exit(EXIT_FAILURE);
}
/* This sequence is necessary, because uselocale() might return
the value LC_GLOBAL_LOCALE, which can't be passed as an
argument to toupper_l(). */
loc = uselocale((locale_t) 0);
if (loc == (locale_t) 0)
err(EXIT_FAILURE, "uselocale");
nloc = duplocale(loc);
if (nloc == (locale_t) 0)
err(EXIT_FAILURE, "duplocale");
for (char *p = argv[1]; *p; p++)
putchar(toupper_l(*p, nloc));
printf("\n");
freelocale(nloc);
exit(EXIT_SUCCESS);
}
π SEE ALSO π
freelocale(3), newlocale(3), setlocale(3), uselocale(3), locale(5), locale(7)
and that's the whole page bestie!! this cutie came to you from Linux man-pages 6.20, dated 2026-02-08, and she said "duplocale(3)" at the top and at the bottom because she's consistent like that. go forth and duplicate your locales responsibly, and don't forget to freelocale(3) when you're done!! bye mwah πβ¨ππ¦πΈ
π¦ where this page comes from
- 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 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2014, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms