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 lo‐
25 cale 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_l() returns a string
28 which is the value corresponding to item for the locale identified by
29 the 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 (%c
46 conversion specification).
47
48 D_FMT (LC_TIME)
49 Return a string that can be used as a format string for strf‐
50 time(3) to represent a date in a locale-specific way (%x conver‐
51 sion specification).
52
53 T_FMT (LC_TIME)
54 Return a string that can be used as a format string for strf‐
55 time(3) to represent a time in a locale-specific way (%X conver‐
56 sion specification).
57
58 AM_STR (LC_TIME)
59 Return a string that represents affix for ante meridiem (before
60 noon, "AM") time. (Used in %p strftime(3) conversion specifica‐
61 tion.)
62
63 PM_STR (LC_TIME)
64 Return a string that represents affix for post meridiem (before
65 midnight, "PM") time. (Used in %p strftime(3) conversion speci‐
66 fication.)
67
68 T_FMT_AMPM (LC_TIME)
69 Return a string that can be used as a format string for strf‐
70 time(3) to represent a time in a.m. or p.m. notation a locale-
71 specific way (%r conversion specification).
72
73 ERA (LC_TIME)
74 Return era description, which contains information about how
75 years are counted and displayed for each era in a locale. Each
76 era description segment shall have the format:
77
78 direction:offset:start_date:end_date:era_name:era_format
79
80 according to the definitions below:
81
82 direction Either a "+" or a "-" character. The "+" means that
83 years increase from the start_date towards the
84 end_date, "-" means the opposite.
85
86 offset The epoch year of the start_date.
87
88 start_date A date in the form yyyy/mm/dd, where yyyy, mm, and
89 dd are the year, month, and day numbers respectively
90 of the start of the era.
91
92 end_date The ending date of the era, in the same format as
93 the start_date, or one of the two special values
94 "-*" (minus infinity) or "+*" (plus infinity).
95
96 era_name The name of the era, corresponding to the %EC strf‐
97 time(3) conversion specification.
98
99 era_format The format of the year in the era, corresponding to
100 the %EY strftime(3) conversion specification.
101
102 Era description segments are separated by semicolons. Most lo‐
103 cales do not define this value. Examples of locales that do de‐
104 fine this value are the Japanese and Thai locales.
105
106 ERA_D_T_FMT (LC_TIME)
107 Return a string that can be used as a format string for strf‐
108 time(3) for alternative representation of time and date in a lo‐
109 cale-specific way (%Ec conversion specification).
110
111 ERA_D_FMT (LC_TIME)
112 Return a string that can be used as a format string for strf‐
113 time(3) for alternative representation of a date in a locale-
114 specific way (%Ex conversion specification).
115
116 ERA_T_FMT (LC_TIME)
117 Return a string that can be used as a format string for strf‐
118 time(3) for alternative representation of a time in a locale-
119 specific way (%EX conversion specification).
120
121 DAY_{1–7} (LC_TIME)
122 Return name of the n-th day of the week. [Warning: this follows
123 the US convention DAY_1 = Sunday, not the international conven‐
124 tion (ISO 8601) that Monday is the first day of the week.]
125 (Used in %A strftime(3) conversion specification.)
126
127 ABDAY_{1–7} (LC_TIME)
128 Return abbreviated name of the n-th day of the week. (Used in
129 %a strftime(3) conversion specification.)
130
131 MON_{1–12} (LC_TIME)
132 Return name of the n-th month. (Used in %B strftime(3) conver‐
133 sion specification.)
134
135 ABMON_{1–12} (LC_TIME)
136 Return abbreviated name of the n-th month. (Used in %b strf‐
137 time(3) conversion specification.)
138
139 RADIXCHAR (LC_NUMERIC)
140 Return radix character (decimal dot, decimal comma, etc.).
141
142 THOUSEP (LC_NUMERIC)
143 Return separator character for thousands (groups of three dig‐
144 its).
145
146 YESEXPR (LC_MESSAGES)
147 Return a regular expression that can be used with the regex(3)
148 function to recognize a positive response to a yes/no question.
149
150 NOEXPR (LC_MESSAGES)
151 Return a regular expression that can be used with the regex(3)
152 function to recognize a negative response to a yes/no question.
153
154 CRNCYSTR (LC_MONETARY)
155 Return the currency symbol, preceded by "-" if the symbol should
156 appear before the value, "+" if the symbol should appear after
157 the value, or "." if the symbol should replace the radix charac‐
158 ter.
159
160 The above list covers just some examples of items that can be re‐
161 quested. For a more detailed list, consult The GNU C Library Reference
162 Manual.
163
165 On success, these functions return a pointer to a string which is the
166 value corresponding to item in the specified locale.
167
168 If no locale has been selected by setlocale(3) for the appropriate cat‐
169 egory, nl_langinfo() return a pointer to the corresponding string in
170 the "C" locale. The same is true of nl_langinfo_l() if locale speci‐
171 fies a locale where langinfo data is not defined.
172
173 If item is not valid, a pointer to an empty string is returned.
174
175 The pointer returned by these functions may point to static data that
176 may be overwritten, or the pointer itself may be invalidated, by a sub‐
177 sequent call to nl_langinfo(), nl_langinfo_l(), or setlocale(3). The
178 same statements apply to nl_langinfo_l() if the locale object referred
179 to by locale is freed or modified by freelocale(3) or newlocale(3).
180
181 POSIX specifies that the application may not modify the string returned
182 by these functions.
183
185 For an explanation of the terms used in this section, see at‐
186 tributes(7).
187
188 ┌──────────────┬───────────────┬────────────────┐
189 │Interface │ Attribute │ Value │
190 ├──────────────┼───────────────┼────────────────┤
191 │nl_langinfo() │ Thread safety │ MT-Safe locale │
192 └──────────────┴───────────────┴────────────────┘
194 POSIX.1-2001, POSIX.1-2008, SUSv2.
195
197 The behavior of nl_langinfo_l() is undefined if locale is the special
198 locale object LC_GLOBAL_LOCALE or is not a valid locale object handle.
199
201 The following program sets the character type and the numeric locale
202 according to the environment and queries the terminal character set and
203 the radix character.
204
205 #include <langinfo.h>
206 #include <locale.h>
207 #include <stdio.h>
208 #include <stdlib.h>
209
210 int
211 main(int argc, char *argv[])
212 {
213 setlocale(LC_CTYPE, "");
214 setlocale(LC_NUMERIC, "");
215
216 printf("%s\n", nl_langinfo(CODESET));
217 printf("%s\n", nl_langinfo(RADIXCHAR));
218
219 exit(EXIT_SUCCESS);
220 }
221
223 locale(1), localeconv(3), setlocale(3), charsets(7), locale(7)
224
225 The GNU C Library Reference Manual
226
228 This page is part of release 5.10 of the Linux man-pages project. A
229 description of the project, information about reporting bugs, and the
230 latest version of this page, can be found at
231 https://www.kernel.org/doc/man-pages/.
232
233
234
235GNU 2020-04-11 NL_LANGINFO(3)