USELOCALE(3POSIX)

πŸ’… USELOCALE(3POSIX) β€” the POSIX Programmer's Manual one

okay bestie, quick vibe check before we start: this is uselocale(3POSIX) from the POSIX Programmer's Manual. Say it with me. πŸŽ€


✨ PROLOG ✨

so like, this manual page is part of the POSIX Programmer's Manual. that's the whole tea. but heads up, fr fr: the Linux implementation of this interface may differ β€” so go consult the corresponding Linux manual page for the deets on Linux behavior β€” or honestly the interface might not even be implemented on Linux at all. 😭 tragic but true.


🌸 NAME 🌸

uselocale β€” use locale in current thread 🧡✨


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <locale.h>

locale_t uselocale(locale_t newloc);

πŸ‘‘ DESCRIPTION πŸ‘‘

so the uselocale() function shall set or query the current locale for the calling thread. that's the whole job. main character energy honestly. πŸ’…

the value for the newloc argument shall be one of the following:

  1. A value returned by the newlocale() or duplocale() functions
  2. The special locale object descriptor LC_GLOBAL_LOCALE
  3. (locale_t)0

now let's break down what each one actually does, because this is the part that matters:

  • If the newloc argument is (locale_t)0, the current locale shall not be changed. this value can be used to query the current locale setting. it's giving "just looking, not touching" πŸ™ˆ
  • If the newloc argument is LC_GLOBAL_LOCALE, any thread-local locale for the calling thread shall be uninstalled. the thread shall again use the global locale as the current locale, and changes to the global locale shall affect the thread. back to the group chat, babes.
  • Otherwise, the locale represented by newloc shall be installed as a thread-local locale, to be used as the current locale for the calling thread. ✨

and here's the iconic part: once the uselocale() function has been called to install a thread-local locale, the behavior of every interface using data from the current locale shall be affected for the calling thread. every single one. no cap. but the current locale for other threads shall remain unchanged β€” your thread's business is your thread's business, periodt. 🫢


πŸ’– RETURN VALUE πŸ’–

upon successful completion, the uselocale() function shall return a handle for the thread-local locale that was in use as the current locale for the calling thread on entry to the function, or LC_GLOBAL_LOCALE if no thread-local locale was in use. like, it tells you what you were on, not what you are on now. very "here's a photo of you before the glow-up" πŸ“Έ

otherwise, uselocale() shall return (locale_t)0 and set errno to indicate the error. 😭


πŸ”₯ ERRORS πŸ”₯

the uselocale() function may fail if:

  • EINVAL β€” newloc is not a valid locale object and is not (locale_t)0.
bestie. read that again. if it's not a real locale object AND it's not (locale_t)0, that's an EINVAL and you did that. πŸ’€

the following sections are informative.


🌈 EXAMPLES 🌈

None. (yes, actually none. the void. the emptiness. iconic of them honestly. πŸ•³οΈ)


πŸ“ APPLICATION USAGE πŸ“

unlike the setlocale() function, the uselocale() function does not allow replacing some locale categories only. so if your app needs to install a locale which differs only in a few categories, you must use newlocale() to change a locale object equivalent to the currently used locale and then install it. it's giving "you can't just swap one category, you gotta build the whole fit" πŸŽ€


🧚 RATIONALE 🧚

None. (again. nothing. we respect the silence. ✨)


⭐ FUTURE DIRECTIONS ⭐

None.


πŸ’œ SEE ALSO πŸ’œ

  • duplocale()
  • freelocale()
  • newlocale()
  • setlocale()

and from 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!! brought to you by IEEE/The Open Group, 2017 β€” yeah, 2017, they were doing thread-local locales before it was cool. mwah. πŸ’…βœ¨