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

πŸ’œ 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) or duplocale(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 by setlocale(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 β€” newloc does 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms