nl_langinfo(3)

๐Ÿ’– nl_langinfo(3) โ€” bestie edition ๐Ÿ’–

okay so you're here for nl_langinfo and nl_langinfo_l, two little functions from the manual page nl_langinfo(3) that know everything about your locale and will spill the tea on request. they live in the Standard C library (libc, -lc). let's go ๐Ÿฆ‹


โœจ NAME โœจ

nl_langinfo, nl_langinfo_l โ€” query language and locale information

๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C library (libc, -lc)

๐ŸŒธ SYNOPSIS ๐ŸŒธ

#include <langinfo.h>

char *nl_langinfo(nl_item item);
char *nl_langinfo_l(nl_item item, locale_t locale);

Feature Test Macro Requirements for glibc (iykyk, see feature_test_macros(7))

  • nl_langinfo_l():
    • Since glibc 2.24:
      • _POSIX_C_SOURCE >= 200809L
    • glibc 2.23 and earlier:
      • _POSIX_C_SOURCE >= 200112L

๐Ÿ‘‘ DESCRIPTION ๐Ÿ‘‘

okay so nl_langinfo() and nl_langinfo_l() are giving you access to locale info in a way more flexible way than localeconv(3) does. like, glow-up levels of flexible.

nl_langinfo() returns a string, and that string is the value corresponding to item in the program's current global locale. nl_langinfo_l() returns a string that's the value corresponding to item for the locale identified by the locale object locale, which was previously created by newlocale(3). and bestie, you can query individual elements and additional elements of the locale categories. obsessed. ๐Ÿ’…

examples for the locale elements you can specify in item using the constants defined in <langinfo.h> are:

  • CODESET (LC_CTYPE) โ€” returns a string with the name of the character encoding used in the selected locale, like "UTF-8", "ISO-8859-1", or "ANSI_X3.4-1968" (better known as US-ASCII). this is the same string you get with "locale charmap". want a whole list of character encoding names? try "locale -m" (see locale(1)). โœจ
  • D_T_FMT (LC_TIME) โ€” returns a string you can use as a format string for strftime(3) to represent time and date in a locale-specific way (that's the %c conversion specification).
  • D_FMT (LC_TIME) โ€” returns a string you can use as a format string for strftime(3) to represent a date in a locale-specific way (%x conversion specification).
  • T_FMT (LC_TIME) โ€” returns a string you can use as a format string for strftime(3) to represent a time in a locale-specific way (%X conversion specification).
  • AM_STR (LC_TIME) โ€” returns a string that represents the affix for ante meridiem (before noon, "AM") time. (used in the %p strftime(3) conversion specification.)
  • PM_STR (LC_TIME) โ€” returns a string that represents the affix for post meridiem (before midnight, "PM") time. (used in the %p strftime(3) conversion specification.)
  • T_FMT_AMPM (LC_TIME) โ€” returns a string you can use as a format string for strftime(3) to represent a time in a.m. or p.m. notation in a locale-specific way (%r conversion specification).
  • ERA (LC_TIME) โ€” returns an era description, which contains info about how years are counted and displayed for each era in a locale. each era description segment shall have the format:
direction:offset:start_date:end_date:era_name:era_format

according to the definitions below:

  • direction โ€” either a "+" or a "-" character. "+" means years increase from the start_date towards the end_date, "-" means the opposite.
  • offset โ€” the epoch year of the start_date.
  • start_date โ€” a date in the form yyyy/mm/dd, where yyyy, mm, and dd are the year, month, and day numbers respectively of the start of the era.
  • end_date โ€” the ending date of the era, in the same format as the start_date, or one of the two special values "-*" (minus infinity) or "+*" (plus infinity).
  • era_name โ€” the name of the era, corresponding to the %EC strftime(3) conversion specification.
  • era_format โ€” the format of the year in the era, corresponding to the %EY strftime(3) conversion specification.

era description segments are separated by semicolons. most locales do not define this value. locales that do define it? the Japanese and Thai locales. ๐ŸŒธ

  • ERA_D_T_FMT (LC_TIME) โ€” returns a string you can use as a format string for strftime(3) for an alternative representation of time and date in a locale-specific way (%Ec conversion specification).
  • ERA_D_FMT (LC_TIME) โ€” returns a string you can use as a format string for strftime(3) for an alternative representation of a date in a locale-specific way (%Ex conversion specification).
  • ERA_T_FMT (LC_TIME) โ€” returns a string you can use as a format string for strftime(3) for an alternative representation of a time in a locale-specific way (%EX conversion specification).
  • DAY_{1โ€“7} (LC_TIME) โ€” returns the name of the n-th day of the week. [โš ๏ธ Warning: this follows the US convention DAY_1 = Sunday, not the international convention (ISO 8601) where Monday is the first day of the week. bestie this trips people up EVERY time, fr fr.] (used in the %A strftime(3) conversion specification.)
  • ABDAY_{1โ€“7} (LC_TIME) โ€” returns the abbreviated name of the n-th day of the week. (used in the %a strftime(3) conversion specification.)
  • MON_{1โ€“12} (LC_TIME) โ€” returns the name of the n-th month. (used in the %B strftime(3) conversion specification.)
  • ABMON_{1โ€“12} (LC_TIME) โ€” returns the abbreviated name of the n-th month. (used in the %b strftime(3) conversion specification.)
  • RADIXCHAR (LC_NUMERIC) โ€” returns the radix character (decimal dot, decimal comma, etc.).
  • THOUSEP (LC_NUMERIC) โ€” returns the separator character for thousands (groups of three digits).
  • YESEXPR (LC_MESSAGES) โ€” returns a regular expression usable with the regex(3) function to recognize a positive response to a yes/no question.
  • NOEXPR (LC_MESSAGES) โ€” returns a regular expression usable with the regex(3) function to recognize a negative response to a yes/no question.
  • CRNCYSTR (LC_MONETARY) โ€” returns the currency symbol, preceded by "-" if the symbol should appear before the value, "+" if the symbol should appear after the value, or "." if the symbol should replace the radix character.

the list above covers just some examples of items you can request. for a more detailed list, go consult The GNU C Library Reference Manual. it's giving reference material. ๐Ÿ“–


๐Ÿซถ RETURN VALUE ๐Ÿซถ

on success, these functions return a pointer to a string which is the value corresponding to item in the specified locale.

if no locale has been selected by setlocale(3) for the appropriate category, nl_langinfo() returns a pointer to the corresponding string in the "C" locale. same deal for nl_langinfo_l() if locale specifies a locale where langinfo data is not defined.

if item is not valid, a pointer to an empty string is returned.

โš ๏ธ okay listen up because this part is important: the pointer returned by these functions may point to static data that may be overwritten, or the pointer itself may be invalidated, by a subsequent call to nl_langinfo(), nl_langinfo_l(), or setlocale(3). and the same statements apply to nl_langinfo_l() if the locale object referred to by locale is freed or modified by freelocale(3) or newlocale(3). do not hoard that pointer, bestie. ๐Ÿ˜ญ

POSIX specifies that the application may not modify the string returned by these functions.

๐Ÿ’… ATTRIBUTES ๐Ÿ’…

for an explanation of the terms used in this section, see attributes(7).

  • nl_langinfo() โ€” Thread safety โ€” MT-Safe locale

โญ STANDARDS โญ

POSIX.1-2008.

๐Ÿ“œ HISTORY ๐Ÿ“œ

POSIX.1-2001, SUSv2.

๐Ÿ™ˆ NOTES ๐Ÿ™ˆ

the behavior of nl_langinfo_l() is undefined if locale is the special locale object LC_GLOBAL_LOCALE or is not a valid locale object handle. undefined behaviour is not a vibe. don't do it. ๐Ÿ’€

๐ŸŒˆ EXAMPLES ๐ŸŒˆ

the following program sets the character type and the numeric locale according to the environment, then queries the terminal character set and the radix character. iconic, honestly.

#include <langinfo.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
    setlocale(LC_CTYPE, "");
    setlocale(LC_NUMERIC, "");

    printf("%s\n", nl_langinfo(CODESET));
    printf("%s\n", nl_langinfo(RADIXCHAR));

    exit(EXIT_SUCCESS);
}

๐ŸŽ€ SEE ALSO ๐ŸŽ€

locale(1), localeconv(3), setlocale(3), charsets(7), locale(7)

The GNU C Library Reference Manual


okay that's the whole page, you ate that ๐Ÿ“ no cap. this was Linux man-pages 6.20, dated 2026-02-08, and it's a nl_langinfo(3) moment for sure. go forth and query your locale, queen ๐Ÿ‘‘๐Ÿ’–


๐Ÿ“ฆ 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: GPL-2.0-or-later
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms