uselocale(3)
π uselocale β the manual page, but make it a group chat π
okay bestie, welcome to uselocale(3), a page from the Library Functions Manual π. it lives in the Standard C library (libc, -lc), and honestly? it's giving "your thread gets its very own locale and the rest of the process can't say anything about it." main character energy fr fr π
β¨ NAME β¨
uselocale β set/get the locale for the calling thread π¦
π LIBRARY π
Standard C library (libc, -lc). yes queen, it's right there in libc, no extra credit required π
πΈ SYNOPSIS πΈ
#include <locale.h>
locale_t uselocale(locale_t newloc);
π§ Feature Test Macro Requirements for glibc π§
(psst β go read feature_test_macros(7) if you're lost, it's the lore):
uselocale():- Since glibc 2.10:
_XOPEN_SOURCE >= 700 - Before glibc 2.10:
_GNU_SOURCE
- Since glibc 2.10:
π DESCRIPTION π
So here's the tea β: uselocale() sets the current locale for the calling thread, and then hands you back the thread's previously current locale. no cap. after a successful call to uselocale(), any calls this thread makes to functions that depend on the locale will act as though the locale has been set to newloc. it's not changing the whole process, bestie, it's just you. thread-local, iconic, we love to see it π
The newloc argument can be one of these:
- A handle returned by a call to
newlocale(3)orduplocale(3)β the calling thread's current locale gets set to that specified locale π - The special locale object handle
LC_GLOBAL_LOCALEβ the calling thread's current locale gets set to the global locale determined bysetlocale(3)π (locale_t) 0β the calling thread's current locale is left unchanged (and the current locale is returned as the function result). so basically a "no thank u, just tell me what's going on" π
π«Ά RETURN VALUE π«Ά
On success, uselocale() returns the locale handle that was set by the previous call to uselocale() in this thread, or LC_GLOBAL_LOCALE if there was no such previous call.
On error, it returns (locale_t) 0, and sets errno to indicate the error π (yes, the classic (locale_t) 0 on error, it's giving "returned a null and left").
π ERRORS π
EINVALβnewlocdoes not refer to a valid locale object. bestie that handle is fake, we noticed π
π STANDARDS π
POSIX.1-2008. certified, official, periodt β¨
π HISTORY π
- glibc 2.3.
POSIX.1-2008.
π NOTES π
okay so here's a thing: unlike setlocale(3), uselocale() does not allow selective replacement of individual locale categories. no picking and choosing here, it's all or nothing π
so if you want a locale that differs in only a few categories from the current one, the move is: use calls to duplocale(3) and newlocale(3) to grab a locale object that's equivalent to the current locale, and then modify the categories you actually want inside that object. slay π₯
π EXAMPLES π
See newlocale(3) and duplocale(3). that's it, that's the example section, go read those two, they understood the assignment πβ¨
π SEE ALSO π
k bye bestie, drink water, free your locale objects, and remember: this page is from Linux man-pages 6.20, dated 2026-02-08 β shoutout to the man-pages girlies for keeping the docs cute and correct ππ¦π
π¦ 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