setlocale(3)
๐ setlocale(3) โ Library Functions Manual ๐
okay bestie, so we're diving into setlocale(3) โ yes the (3) means it lives in section 3 of the manual, the Library Functions Manual, aka where the C library girlies hang out โจ
๐ธ NAME ๐ธ
setlocale โ set the current locale ๐
๐ LIBRARY ๐
Standard C library (libc, -lc) ๐ซถ
โจ SYNOPSIS โจ
#include <locale.h>
char *setlocale(int category, const char *_Nullable locale);
๐ฆ DESCRIPTION ๐ฆ
so setlocale() is the function you call to set or query your program's current locale. that's it, that's the whole job ๐
If locale is not NULL, your program's current locale gets modified according to the args. The category argument is the one deciding which parts of the program's current locale should be modified. Here's the whole roster, no skips:
LC_ALLโ All of the locale ๐LC_ADDRESSโ Formatting of addresses and geography-related items (*)LC_COLLATEโ String collationLC_CTYPEโ Character classificationLC_IDENTIFICATIONโ Metadata describing the locale (*)LC_MEASUREMENTโ Settings related to measurements (metric versus US customary) (*)LC_MESSAGESโ Localizable natural-language messagesLC_MONETARYโ Formatting of monetary valuesLC_NAMEโ Formatting of salutations for persons (*)LC_NUMERICโ Formatting of nonmonetary numeric valuesLC_PAPERโ Settings related to the standard paper size (*)LC_TELEPHONEโ Formats to be used with telephone services (*)LC_TIMEโ Formatting of date and time values
The categories marked with an asterisk in the above table are GNU extensions, okay? not universal, not portable, they're the bonus DLC. For further information on these locale categories, see locale(7) ๐ง
Now the locale argument โ it's a pointer to a character string holding the required setting of category. That string is either a well-known constant like "C" or "da_DK" (see below bestie, we get there), or an opaque string that was returned by another call of setlocale() ๐ซ
If locale is an empty string, "", then every part of the locale that should be modified gets set according to the environment variables. The details are implementation-dependent โ that's the vibe. For glibc, first (regardless of category), the environment variable LC_ALL is inspected, next the environment variable with the same name as the category (see the table above), and finally the environment variable LANG. The first existing environment variable is used. If its value is not a valid locale specification, the locale is unchanged, and setlocale() returns NULL ๐ญ
The locale "C" or "POSIX" is a portable locale; it exists on all conforming systems. universal icon behavior fr fr ๐
A locale name is typically of the form language[_territory][.codeset][@modifier], where language is an ISO 639 language code, territory is an ISO 3166 country code, and codeset is a character set or encoding identifier like ISO-8859-1 or UTF-8. For a list of all supported locales, try "locale -a" (see locale(1)) ๐ฅ
If locale is NULL, the current locale is only queried, not modified. it's just a lil vibe check, no changes bestie ๐
On startup of the main program, the portable "C" locale is selected as default. A program may be made portable to all locales by calling:
setlocale(LC_ALL, "");
after program initialization, and then:
- using the values returned from a
localeconv(3)call for locale-dependent information; - using the multibyte and wide character functions for text processing if
MB_CUR_MAX > 1; - using
strcoll(3)andstrxfrm(3)to compare strings; and - using
wcscoll(3)andwcsxfrm(3)to compare wide-character strings.
that's the portability starter pack, no cap ๐
๐ซถ RETURN VALUE ๐ซถ
A successful call to setlocale() returns an opaque string that corresponds to the locale set. This string may be allocated in static storage โ noted. The string returned is such that a subsequent call with that string and its associated category will restore that part of the process's locale. The return value is NULL if the request cannot be honored ๐
โญ ATTRIBUTES โญ
For an explanation of the terms used in this section, see attributes(7).
- Interface:
setlocale()โ Attribute: Thread safety โ Value:MT-Unsafe const:locale env
ok so the thread-safety tea is: MT-Unsafe const:locale env. write that down ๐
๐ STANDARDS ๐
C11, POSIX.1-2008.
๐ Categories ๐
LC_ALLLC_COLLATELC_CTYPELC_MONETARYLC_NUMERICLC_TIME
โ C11, POSIX.1-2008.
LC_MESSAGES
โ POSIX.1-2008.
- Others: โ GNU.
๐ HISTORY ๐
POSIX.1-2001, C89.
๐ Categories ๐
LC_ALLLC_COLLATELC_CTYPELC_MONETARYLC_NUMERICLC_TIME
โ C89, POSIX.1-2001.
LC_MESSAGES
โ POSIX.1-2001.
- Others: โ GNU.
๐ SEE ALSO ๐
locale(1), localedef(1), isalpha(3), localeconv(3), nl_langinfo(3), rpmatch(3), strcoll(3), strftime(3), charsets(7), locale(7)
and that's the whole page bestie, you ate that ๐
โจ this was setlocale(3) from Linux man-pages 6.20, dated 2026-02-08 โ go forth and localize, you gorgeous main character ๐ฆ๐๐
๐ฆ 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 1993, Thomas Koenig <ig25@rz.uni-karlsruhe.de>
- Copyright 1999, Bruno Haible <bruno@clisp.org>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms