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 collation
  • LC_CTYPE โ€” Character classification
  • LC_IDENTIFICATION โ€” Metadata describing the locale (*)
  • LC_MEASUREMENT โ€” Settings related to measurements (metric versus US customary) (*)
  • LC_MESSAGES โ€” Localizable natural-language messages
  • LC_MONETARY โ€” Formatting of monetary values
  • LC_NAME โ€” Formatting of salutations for persons (*)
  • LC_NUMERIC โ€” Formatting of nonmonetary numeric values
  • LC_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) and strxfrm(3) to compare strings; and
  • using wcscoll(3) and wcsxfrm(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_ALL
  • LC_COLLATE
  • LC_CTYPE
  • LC_MONETARY
  • LC_NUMERIC
  • LC_TIME

โ†’ C11, POSIX.1-2008.

  • LC_MESSAGES

โ†’ POSIX.1-2008.

  • Others: โ†’ GNU.

๐Ÿ’œ HISTORY ๐Ÿ’œ

POSIX.1-2001, C89.

๐ŸŽ€ Categories ๐ŸŽ€

  • LC_ALL
  • LC_COLLATE
  • LC_CTYPE
  • LC_MONETARY
  • LC_NUMERIC
  • LC_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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms