1NL_LANGINFO(3) Linux Programmer's Manual NL_LANGINFO(3)
2
3
4
6 nl_langinfo, nl_langinfo_l - query language and locale information
7
9 #include <langinfo.h>
10
11 char *nl_langinfo(nl_item item);
12
13 char *nl_langinfo_l(nl_item item, locale_t locale);
14
15 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17 nl_langinfo_l():
18 Since glibc 2.24:
19 _POSIX_C_SOURCE >= 200809L
20 Glibc 2.23 and earlier:
21 _POSIX_C_SOURCE >= 200112L
22
24 The nl_langinfo() and nl_langinfo_l() functions provide access to
25 locale information in a more flexible way than localeconv(3). nl_lang‐
26 info() returns a string which is the value corresponding to item in the
27 program's current global locale. nl_langinfo() returns a string which
28 is the value corresponding to item for the locale identified by the
29 locale object locale, which was previously created by newlocale(1).
30 Individual and additional elements of the locale categories can be
31 queried.
32
33 Examples for the locale elements that can be specified in item using
34 the constants defined in <langinfo.h> are:
35
36 CODESET (LC_CTYPE)
37 Return a string with the name of the character encoding used in
38 the selected locale, such as "UTF-8", "ISO-8859-1", or
39 "ANSI_X3.4-1968" (better known as US-ASCII). This is the same
40 string that you get with "locale charmap". For a list of char‐
41 acter encoding names, try "locale -m" (see locale(1)).
42
43 D_T_FMT (LC_TIME)
44 Return a string that can be used as a format string for strf‐
45 time(3) to represent time and date in a locale-specific way.
46
47 D_FMT (LC_TIME)
48 Return a string that can be used as a format string for strf‐
49 time(3) to represent a date in a locale-specific way.
50
51 T_FMT (LC_TIME)
52 Return a string that can be used as a format string for strf‐
53 time(3) to represent a time in a locale-specific way.
54
55 DAY_{1–7} (LC_TIME)
56 Return name of the n-th day of the week. [Warning: this follows
57 the US convention DAY_1 = Sunday, not the international conven‐
58 tion (ISO 8601) that Monday is the first day of the week.]
59
60 ABDAY_{1–7} (LC_TIME)
61 Return abbreviated name of the n-th day of the week.
62
63 MON_{1–12} (LC_TIME)
64 Return name of the n-th month.
65
66 ABMON_{1–12} (LC_TIME)
67 Return abbreviated name of the n-th month.
68
69 RADIXCHAR (LC_NUMERIC)
70 Return radix character (decimal dot, decimal comma, etc.).
71
72 THOUSEP (LC_NUMERIC)
73 Return separator character for thousands (groups of three dig‐
74 its).
75
76 YESEXPR (LC_MESSAGES)
77 Return a regular expression that can be used with the regex(3)
78 function to recognize a positive response to a yes/no question.
79
80 NOEXPR (LC_MESSAGES)
81 Return a regular expression that can be used with the regex(3)
82 function to recognize a negative response to a yes/no question.
83
84 CRNCYSTR (LC_MONETARY)
85 Return the currency symbol, preceded by "-" if the symbol should
86 appear before the value, "+" if the symbol should appear after
87 the value, or "." if the symbol should replace the radix charac‐
88 ter.
89
90 The above list covers just some examples of items that can be
91 requested. For a more detailed list, consult The GNU C Library Refer‐
92 ence Manual.
93
95 On success, these functions return a pointer to a string which is the
96 value corresponding to item in the specified locale.
97
98 If no locale has been selected by setlocale(3) for the appropriate cat‐
99 egory, nl_langinfo() return a pointer to the corresponding string in
100 the "C" locale. The same is true of nl_langinfo_l() if locale speci‐
101 fies a locale where langinfo data is not defined.
102
103 If item is not valid, a pointer to an empty string is returned.
104
105 The pointer returned by these functions may point to static data that
106 may be overwritten, or the pointer itself may be invalidated, by a sub‐
107 sequent call to nl_langinfo(), nl_langinfo_l(), or setlocale(3). The
108 same statements apply to nl_langinfo_l() if the locale object referred
109 to by locale is freed or modified by freelocale(3) or newlocale(3).
110
111 POSIX specifies that the application may not modify the string returned
112 by these functions.
113
114 Codeset for en_US defaults to ISO-8859-1 (Latin-1). The Latin-1
115 default has historical reasons, since all Unix systems originally used
116 only 8-bit character encoding. For more information about ISO-8859-1
117 see charsets(7).
118
120 For an explanation of the terms used in this section, see
121 attributes(7).
122
123 ┌──────────────┬───────────────┬────────────────┐
124 │Interface │ Attribute │ Value │
125 ├──────────────┼───────────────┼────────────────┤
126 │nl_langinfo() │ Thread safety │ MT-Safe locale │
127 └──────────────┴───────────────┴────────────────┘
129 POSIX.1-2001, POSIX.1-2008, SUSv2.
130
132 The behavior of nl_langinfo_l() is undefined if locale is the special
133 locale object LC_GLOBAL_LOCALE or is not a valid locale object handle.
134
136 The following program sets the character type and the numeric locale
137 according to the environment and queries the terminal character set and
138 the radix character.
139
140 #include <langinfo.h>
141 #include <locale.h>
142 #include <stdio.h>
143 #include <stdlib.h>
144
145 int
146 main(int argc, char *argv[])
147 {
148 setlocale(LC_CTYPE, "");
149 setlocale(LC_NUMERIC, "");
150
151 printf("%s\n", nl_langinfo(CODESET));
152 printf("%s\n", nl_langinfo(RADIXCHAR));
153
154 exit(EXIT_SUCCESS);
155 }
156
158 locale(1), localeconv(3), setlocale(3), charsets(7), locale(7)
159
160 The GNU C Library Reference Manual
161
163 This page is part of release 4.15 of the Linux man-pages project. A
164 description of the project, information about reporting bugs, and the
165 latest version of this page, can be found at
166 https://www.kernel.org/doc/man-pages/.
167
168
169
170GNU 2017-09-15 NL_LANGINFO(3)