Skip to content

Commit f67bacb

Browse files
committed
Define xlocale and langinfo interfaces
There are many constants defined by langinfo, but we have the new types, locale_t and nl_item. We also have several functions, not all of which exist for every platform: nl_langinfo nl_langinfo_l newlocale duplocale freelocale uselocale querylocale
1 parent f288e18 commit f67bacb

File tree

13 files changed

+580
-0
lines changed

13 files changed

+580
-0
lines changed

libc-test/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ fn main() {
100100
if android {
101101
cfg.header("arpa/inet.h");
102102
cfg.header("time64.h");
103+
cfg.header("xlocale.h");
103104
} else if !windows {
104105
cfg.header("glob.h");
105106
cfg.header("ifaddrs.h");
106107
cfg.header("sys/statvfs.h");
108+
cfg.header("langinfo.h");
107109

108110
if !openbsd && !freebsd && !dragonfly {
109111
cfg.header("sys/quota.h");
@@ -114,6 +116,7 @@ fn main() {
114116

115117
if !netbsd && !openbsd {
116118
cfg.header("execinfo.h");
119+
cfg.header("xlocale.h");
117120
}
118121
}
119122
}

src/unix/bsd/apple/mod.rs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub type fsblkcnt_t = ::c_uint;
1818
pub type fsfilcnt_t = ::c_uint;
1919
pub type speed_t = ::c_ulong;
2020
pub type tcflag_t = ::c_ulong;
21+
pub type nl_item = ::c_int;
2122

2223
pub enum timezone {}
2324

@@ -286,6 +287,88 @@ s! {
286287
}
287288
}
288289

290+
pub const LC_COLLATE_MASK: ::c_int = (1 << 0);
291+
pub const LC_CTYPE_MASK: ::c_int = (1 << 1);
292+
pub const LC_MESSAGES_MASK: ::c_int = (1 << 2);
293+
pub const LC_MONETARY_MASK: ::c_int = (1 << 3);
294+
pub const LC_NUMERIC_MASK: ::c_int = (1 << 4);
295+
pub const LC_TIME_MASK: ::c_int = (1 << 5);
296+
pub const LC_ALL_MASK: ::c_int = LC_COLLATE_MASK
297+
| LC_CTYPE_MASK
298+
| LC_MESSAGES_MASK
299+
| LC_MONETARY_MASK
300+
| LC_NUMERIC_MASK
301+
| LC_TIME_MASK;
302+
303+
pub const CODESET: ::nl_item = 0;
304+
pub const D_T_FMT: ::nl_item = 1;
305+
pub const D_FMT: ::nl_item = 2;
306+
pub const T_FMT: ::nl_item = 3;
307+
pub const T_FMT_AMPM: ::nl_item = 4;
308+
pub const AM_STR: ::nl_item = 5;
309+
pub const PM_STR: ::nl_item = 6;
310+
311+
pub const DAY_1: ::nl_item = 7;
312+
pub const DAY_2: ::nl_item = 8;
313+
pub const DAY_3: ::nl_item = 9;
314+
pub const DAY_4: ::nl_item = 10;
315+
pub const DAY_5: ::nl_item = 11;
316+
pub const DAY_6: ::nl_item = 12;
317+
pub const DAY_7: ::nl_item = 13;
318+
319+
pub const ABDAY_1: ::nl_item = 14;
320+
pub const ABDAY_2: ::nl_item = 15;
321+
pub const ABDAY_3: ::nl_item = 16;
322+
pub const ABDAY_4: ::nl_item = 17;
323+
pub const ABDAY_5: ::nl_item = 18;
324+
pub const ABDAY_6: ::nl_item = 19;
325+
pub const ABDAY_7: ::nl_item = 20;
326+
327+
pub const MON_1: ::nl_item = 21;
328+
pub const MON_2: ::nl_item = 22;
329+
pub const MON_3: ::nl_item = 23;
330+
pub const MON_4: ::nl_item = 24;
331+
pub const MON_5: ::nl_item = 25;
332+
pub const MON_6: ::nl_item = 26;
333+
pub const MON_7: ::nl_item = 27;
334+
pub const MON_8: ::nl_item = 28;
335+
pub const MON_9: ::nl_item = 29;
336+
pub const MON_10: ::nl_item = 30;
337+
pub const MON_11: ::nl_item = 31;
338+
pub const MON_12: ::nl_item = 32;
339+
340+
pub const ABMON_1: ::nl_item = 33;
341+
pub const ABMON_2: ::nl_item = 34;
342+
pub const ABMON_3: ::nl_item = 35;
343+
pub const ABMON_4: ::nl_item = 36;
344+
pub const ABMON_5: ::nl_item = 37;
345+
pub const ABMON_6: ::nl_item = 38;
346+
pub const ABMON_7: ::nl_item = 39;
347+
pub const ABMON_8: ::nl_item = 40;
348+
pub const ABMON_9: ::nl_item = 41;
349+
pub const ABMON_10: ::nl_item = 42;
350+
pub const ABMON_11: ::nl_item = 43;
351+
pub const ABMON_12: ::nl_item = 44;
352+
353+
pub const ERA: ::nl_item = 45;
354+
pub const ERA_D_FMT: ::nl_item = 46;
355+
pub const ERA_D_T_FMT: ::nl_item = 47;
356+
pub const ERA_T_FMT: ::nl_item = 48;
357+
pub const ALT_DIGITS: ::nl_item = 49;
358+
359+
pub const RADIXCHAR: ::nl_item = 50;
360+
pub const THOUSEP: ::nl_item = 51;
361+
362+
pub const YESEXPR: ::nl_item = 52;
363+
pub const NOEXPR: ::nl_item = 53;
364+
365+
pub const YESSTR: ::nl_item = 54;
366+
pub const NOSTR: ::nl_item = 55;
367+
368+
pub const CRNCYSTR: ::nl_item = 56;
369+
370+
pub const D_MD_ORDER: ::nl_item = 57;
371+
289372
pub const EXIT_FAILURE: ::c_int = 1;
290373
pub const EXIT_SUCCESS: ::c_int = 0;
291374
pub const RAND_MAX: ::c_int = 2147483647;
@@ -1027,6 +1110,14 @@ extern {
10271110
name: *mut ::c_char,
10281111
termp: *mut termios,
10291112
winp: *mut ::winsize) -> ::pid_t;
1113+
pub fn duplocale(base: ::locale_t) -> ::locale_t;
1114+
pub fn freelocale(loc: ::locale_t) -> ::c_int;
1115+
pub fn localeconv_l(loc: ::locale_t) -> *mut lconv;
1116+
pub fn newlocale(mask: ::c_int,
1117+
locale: *const ::c_char,
1118+
base: ::locale_t) -> ::locale_t;
1119+
pub fn uselocale(loc: ::locale_t) -> ::locale_t;
1120+
pub fn querylocale(mask: ::c_int, loc: ::locale_t) -> *const ::c_char;
10301121
}
10311122

10321123
cfg_if! {

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub type pthread_rwlock_t = *mut ::c_void;
99
pub type pthread_key_t = ::c_int;
1010
pub type tcflag_t = ::c_uint;
1111
pub type speed_t = ::c_uint;
12+
pub type nl_item = ::c_int;
1213

1314
pub enum timezone {}
1415

@@ -149,6 +150,101 @@ s! {
149150
}
150151
}
151152

153+
pub const LC_COLLATE_MASK: ::c_int = (1 << 0);
154+
pub const LC_CTYPE_MASK: ::c_int = (1 << 1);
155+
pub const LC_MESSAGES_MASK: ::c_int = (1 << 2);
156+
pub const LC_MONETARY_MASK: ::c_int = (1 << 3);
157+
pub const LC_NUMERIC_MASK: ::c_int = (1 << 4);
158+
pub const LC_TIME_MASK: ::c_int = (1 << 5);
159+
pub const LC_ALL_MASK: ::c_int = LC_COLLATE_MASK
160+
| LC_CTYPE_MASK
161+
| LC_MESSAGES_MASK
162+
| LC_MONETARY_MASK
163+
| LC_NUMERIC_MASK
164+
| LC_TIME_MASK;
165+
166+
pub const CODESET: ::nl_item = 0;
167+
pub const D_T_FMT: ::nl_item = 1;
168+
pub const D_FMT: ::nl_item = 2;
169+
pub const T_FMT: ::nl_item = 3;
170+
pub const T_FMT_AMPM: ::nl_item = 4;
171+
pub const AM_STR: ::nl_item = 5;
172+
pub const PM_STR: ::nl_item = 6;
173+
174+
pub const DAY_1: ::nl_item = 7;
175+
pub const DAY_2: ::nl_item = 8;
176+
pub const DAY_3: ::nl_item = 9;
177+
pub const DAY_4: ::nl_item = 10;
178+
pub const DAY_5: ::nl_item = 11;
179+
pub const DAY_6: ::nl_item = 12;
180+
pub const DAY_7: ::nl_item = 13;
181+
182+
pub const ABDAY_1: ::nl_item = 14;
183+
pub const ABDAY_2: ::nl_item = 15;
184+
pub const ABDAY_3: ::nl_item = 16;
185+
pub const ABDAY_4: ::nl_item = 17;
186+
pub const ABDAY_5: ::nl_item = 18;
187+
pub const ABDAY_6: ::nl_item = 19;
188+
pub const ABDAY_7: ::nl_item = 20;
189+
190+
pub const MON_1: ::nl_item = 21;
191+
pub const MON_2: ::nl_item = 22;
192+
pub const MON_3: ::nl_item = 23;
193+
pub const MON_4: ::nl_item = 24;
194+
pub const MON_5: ::nl_item = 25;
195+
pub const MON_6: ::nl_item = 26;
196+
pub const MON_7: ::nl_item = 27;
197+
pub const MON_8: ::nl_item = 28;
198+
pub const MON_9: ::nl_item = 29;
199+
pub const MON_10: ::nl_item = 30;
200+
pub const MON_11: ::nl_item = 31;
201+
pub const MON_12: ::nl_item = 32;
202+
203+
pub const ABMON_1: ::nl_item = 33;
204+
pub const ABMON_2: ::nl_item = 34;
205+
pub const ABMON_3: ::nl_item = 35;
206+
pub const ABMON_4: ::nl_item = 36;
207+
pub const ABMON_5: ::nl_item = 37;
208+
pub const ABMON_6: ::nl_item = 38;
209+
pub const ABMON_7: ::nl_item = 39;
210+
pub const ABMON_8: ::nl_item = 40;
211+
pub const ABMON_9: ::nl_item = 41;
212+
pub const ABMON_10: ::nl_item = 42;
213+
pub const ABMON_11: ::nl_item = 43;
214+
pub const ABMON_12: ::nl_item = 44;
215+
216+
pub const ERA: ::nl_item = 45;
217+
pub const ERA_D_FMT: ::nl_item = 46;
218+
pub const ERA_D_T_FMT: ::nl_item = 47;
219+
pub const ERA_T_FMT: ::nl_item = 48;
220+
pub const ALT_DIGITS: ::nl_item = 49;
221+
222+
pub const RADIXCHAR: ::nl_item = 50;
223+
pub const THOUSEP: ::nl_item = 51;
224+
225+
pub const YESEXPR: ::nl_item = 52;
226+
pub const NOEXPR: ::nl_item = 53;
227+
228+
pub const YESSTR: ::nl_item = 54;
229+
pub const NOSTR: ::nl_item = 55;
230+
231+
pub const CRNCYSTR: ::nl_item = 56;
232+
233+
pub const D_MD_ORDER: ::nl_item = 57;
234+
235+
pub const ALTMON_1: ::nl_item = 58;
236+
pub const ALTMON_2: ::nl_item = 59;
237+
pub const ALTMON_3: ::nl_item = 60;
238+
pub const ALTMON_4: ::nl_item = 61;
239+
pub const ALTMON_5: ::nl_item = 62;
240+
pub const ALTMON_6: ::nl_item = 63;
241+
pub const ALTMON_7: ::nl_item = 64;
242+
pub const ALTMON_8: ::nl_item = 65;
243+
pub const ALTMON_9: ::nl_item = 66;
244+
pub const ALTMON_10: ::nl_item = 67;
245+
pub const ALTMON_11: ::nl_item = 68;
246+
pub const ALTMON_12: ::nl_item = 69;
247+
152248
pub const EXIT_FAILURE: ::c_int = 1;
153249
pub const EXIT_SUCCESS: ::c_int = 0;
154250
pub const EOF: ::c_int = -1;
@@ -627,6 +723,14 @@ extern {
627723
name: *mut ::c_char,
628724
termp: *mut termios,
629725
winp: *mut ::winsize) -> ::pid_t;
726+
pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t) -> *mut ::c_char;
727+
pub fn duplocale(base: ::locale_t) -> ::locale_t;
728+
pub fn freelocale(loc: ::locale_t) -> ::c_int;
729+
pub fn newlocale(mask: ::c_int,
730+
locale: *const ::c_char,
731+
base: ::locale_t) -> ::locale_t;
732+
pub fn uselocale(loc: ::locale_t) -> ::locale_t;
733+
pub fn querylocale(mask: ::c_int, loc: ::locale_t) -> *const ::c_char;
630734
}
631735

632736
cfg_if! {

src/unix/bsd/openbsdlike/bitrig.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,40 @@ s! {
135135
}
136136
}
137137

138+
pub const LC_COLLATE_MASK: ::c_int = (1 << 0);
139+
pub const LC_CTYPE_MASK: ::c_int = (1 << 1);
140+
pub const LC_MESSAGES_MASK: ::c_int = (1 << 2);
141+
pub const LC_MONETARY_MASK: ::c_int = (1 << 3);
142+
pub const LC_NUMERIC_MASK: ::c_int = (1 << 4);
143+
pub const LC_TIME_MASK: ::c_int = (1 << 5);
144+
pub const LC_ALL_MASK: ::c_int = LC_COLLATE_MASK
145+
| LC_CTYPE_MASK
146+
| LC_MESSAGES_MASK
147+
| LC_MONETARY_MASK
148+
| LC_NUMERIC_MASK
149+
| LC_TIME_MASK;
150+
151+
pub const ERA: ::nl_item = 52;
152+
pub const ERA_D_FMT: ::nl_item = 53;
153+
pub const ERA_D_T_FMT: ::nl_item = 54;
154+
pub const ERA_T_FMT: ::nl_item = 55;
155+
pub const ALT_DIGITS: ::nl_item = 56;
156+
157+
pub const D_MD_ORDER: ::nl_item = 57;
158+
159+
pub const ALTMON_1: ::nl_item = 58;
160+
pub const ALTMON_2: ::nl_item = 59;
161+
pub const ALTMON_3: ::nl_item = 60;
162+
pub const ALTMON_4: ::nl_item = 61;
163+
pub const ALTMON_5: ::nl_item = 62;
164+
pub const ALTMON_6: ::nl_item = 63;
165+
pub const ALTMON_7: ::nl_item = 64;
166+
pub const ALTMON_8: ::nl_item = 65;
167+
pub const ALTMON_9: ::nl_item = 66;
168+
pub const ALTMON_10: ::nl_item = 67;
169+
pub const ALTMON_11: ::nl_item = 68;
170+
pub const ALTMON_12: ::nl_item = 69;
171+
138172
pub const O_CLOEXEC: ::c_int = 0x10000;
139173

140174
pub const MS_SYNC : ::c_int = 0x0002;
@@ -271,4 +305,12 @@ extern {
271305
newp: *mut ::c_void,
272306
newlen: ::size_t)
273307
-> ::c_int;
308+
pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t) -> *mut ::c_char;
309+
pub fn duplocale(base: ::locale_t) -> ::locale_t;
310+
pub fn freelocale(loc: ::locale_t) -> ::c_int;
311+
pub fn newlocale(mask: ::c_int,
312+
locale: *const ::c_char,
313+
base: ::locale_t) -> ::locale_t;
314+
pub fn uselocale(loc: ::locale_t) -> ::locale_t;
315+
pub fn querylocale(mask: ::c_int, loc: ::locale_t) -> *const ::c_char;
274316
}

src/unix/bsd/openbsdlike/mod.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub type pthread_key_t = ::c_int;
88
pub type rlim_t = u64;
99
pub type speed_t = ::c_uint;
1010
pub type tcflag_t = ::c_uint;
11+
pub type nl_item = c_long;
1112

1213
pub enum timezone {}
1314

@@ -51,6 +52,65 @@ s! {
5152
}
5253
}
5354

55+
pub const D_T_FMT: ::nl_item = 0;
56+
pub const D_FMT: ::nl_item = 1;
57+
pub const T_FMT: ::nl_item = 2;
58+
pub const T_FMT_AMPM: ::nl_item = 3;
59+
pub const AM_STR: ::nl_item = 4;
60+
pub const PM_STR: ::nl_item = 5;
61+
62+
pub const DAY_1: ::nl_item = 6;
63+
pub const DAY_2: ::nl_item = 7;
64+
pub const DAY_3: ::nl_item = 8;
65+
pub const DAY_4: ::nl_item = 9;
66+
pub const DAY_5: ::nl_item = 10;
67+
pub const DAY_6: ::nl_item = 11;
68+
pub const DAY_7: ::nl_item = 12;
69+
70+
pub const ABDAY_1: ::nl_item = 13;
71+
pub const ABDAY_2: ::nl_item = 14;
72+
pub const ABDAY_3: ::nl_item = 15;
73+
pub const ABDAY_4: ::nl_item = 16;
74+
pub const ABDAY_5: ::nl_item = 17;
75+
pub const ABDAY_6: ::nl_item = 18;
76+
pub const ABDAY_7: ::nl_item = 19;
77+
78+
pub const MON_1: ::nl_item = 20;
79+
pub const MON_2: ::nl_item = 21;
80+
pub const MON_3: ::nl_item = 22;
81+
pub const MON_4: ::nl_item = 23;
82+
pub const MON_5: ::nl_item = 24;
83+
pub const MON_6: ::nl_item = 25;
84+
pub const MON_7: ::nl_item = 26;
85+
pub const MON_8: ::nl_item = 27;
86+
pub const MON_9: ::nl_item = 28;
87+
pub const MON_10: ::nl_item = 29;
88+
pub const MON_11: ::nl_item = 30;
89+
pub const MON_12: ::nl_item = 31;
90+
91+
pub const ABMON_1: ::nl_item = 32;
92+
pub const ABMON_2: ::nl_item = 33;
93+
pub const ABMON_3: ::nl_item = 34;
94+
pub const ABMON_4: ::nl_item = 35;
95+
pub const ABMON_5: ::nl_item = 36;
96+
pub const ABMON_6: ::nl_item = 37;
97+
pub const ABMON_7: ::nl_item = 38;
98+
pub const ABMON_8: ::nl_item = 39;
99+
pub const ABMON_9: ::nl_item = 40;
100+
pub const ABMON_10: ::nl_item = 41;
101+
pub const ABMON_11: ::nl_item = 42;
102+
pub const ABMON_12: ::nl_item = 43;
103+
104+
pub const RADIXCHAR: ::nl_item = 44;
105+
pub const THOUSEP: ::nl_item = 45;
106+
pub const YESSTR: ::nl_item = 46;
107+
pub const YESEXPR: ::nl_item = 47;
108+
pub const NOSTR: ::nl_item = 48;
109+
pub const NOEXPR: ::nl_item = 49;
110+
pub const CRNCYSTR: ::nl_item = 50;
111+
112+
pub const CODESET: ::nl_item = 51;
113+
54114
pub const EXIT_FAILURE : ::c_int = 1;
55115
pub const EXIT_SUCCESS : ::c_int = 0;
56116
pub const RAND_MAX : ::c_int = 2147483647;

0 commit comments

Comments
 (0)