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
- Since glibc 2.24:
๐ 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"(seelocale(1)). โจD_T_FMT(LC_TIME) โ returns a string you can use as a format string forstrftime(3)to represent time and date in a locale-specific way (that's the%cconversion specification).D_FMT(LC_TIME) โ returns a string you can use as a format string forstrftime(3)to represent a date in a locale-specific way (%xconversion specification).T_FMT(LC_TIME) โ returns a string you can use as a format string forstrftime(3)to represent a time in a locale-specific way (%Xconversion specification).AM_STR(LC_TIME) โ returns a string that represents the affix for ante meridiem (before noon, "AM") time. (used in the%pstrftime(3)conversion specification.)PM_STR(LC_TIME) โ returns a string that represents the affix for post meridiem (before midnight, "PM") time. (used in the%pstrftime(3)conversion specification.)T_FMT_AMPM(LC_TIME) โ returns a string you can use as a format string forstrftime(3)to represent a time in a.m. or p.m. notation in a locale-specific way (%rconversion 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 formyyyy/mm/dd, whereyyyy,mm, andddare 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%ECstrftime(3)conversion specification.era_formatโ the format of the year in the era, corresponding to the%EYstrftime(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 forstrftime(3)for an alternative representation of time and date in a locale-specific way (%Ecconversion specification).ERA_D_FMT(LC_TIME) โ returns a string you can use as a format string forstrftime(3)for an alternative representation of a date in a locale-specific way (%Exconversion specification).ERA_T_FMT(LC_TIME) โ returns a string you can use as a format string forstrftime(3)for an alternative representation of a time in a locale-specific way (%EXconversion specification).DAY_{1โ7}(LC_TIME) โ returns the name of the n-th day of the week. [โ ๏ธ Warning: this follows the US conventionDAY_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%Astrftime(3)conversion specification.)ABDAY_{1โ7}(LC_TIME) โ returns the abbreviated name of the n-th day of the week. (used in the%astrftime(3)conversion specification.)MON_{1โ12}(LC_TIME) โ returns the name of the n-th month. (used in the%Bstrftime(3)conversion specification.)ABMON_{1โ12}(LC_TIME) โ returns the abbreviated name of the n-th month. (used in the%bstrftime(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 theregex(3)function to recognize a positive response to a yes/no question.NOEXPR(LC_MESSAGES) โ returns a regular expression usable with theregex(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 tonl_langinfo(),nl_langinfo_l(), orsetlocale(3). and the same statements apply tonl_langinfo_l()if the locale object referred to by locale is freed or modified byfreelocale(3)ornewlocale(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
- Copyright 2001, Markus Kuhn <mkuhn@acm.org>
- Copyright 2006, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms