1 #include <locale.h>
2 #include <langinfo.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <wctype.h>
6 #include <string.h>
7 #include <stdint.h>
8
9 static const char *_empty_str = "";
10 static const char *_C_name = "C";
11
_ToWChar(const char * buf,wchar_t * wbuf,size_t wbufSize)12 static wchar_t* _ToWChar(const char* buf, wchar_t *wbuf, size_t wbufSize) {
13 wchar_t *wcur = wbuf;
14 wchar_t *wend = wbuf + wbufSize - 1;
15 for (; wcur != wend && *buf != 0; ++buf, ++wcur)
16 *wcur = *buf;
17 *wcur = 0;
18 return wbuf;
19 }
20
21 #if 0
22 struct _Locale_ctype
23 {
24 locale_t __cloc;
25 };
26
27 struct _Locale_numeric
28 {
29 locale_t __cloc;
30 };
31
32 struct _Locale_time
33 {
34 locale_t __cloc;
35 };
36
37 struct _Locale_collate
38 {
39 locale_t __cloc;
40 };
41
42 struct _Locale_monetary
43 {
44 locale_t __cloc;
45 };
46
47 struct _Locale_messages
48 {
49 locale_t __cloc;
50 };
51 #endif
52
_Locale_init()53 void _Locale_init()
54 {}
55
_Locale_final()56 void _Locale_final()
57 {}
58
_Locale_ctype_create(const char * nm,struct _Locale_name_hint * hint,int * __err_code)59 struct _Locale_ctype *_Locale_ctype_create(const char *nm, struct _Locale_name_hint* hint,
60 int *__err_code) {
61 *__err_code = _STLP_LOC_UNKNOWN_NAME;
62 return (struct _Locale_ctype*)newlocale(LC_CTYPE_MASK, nm, NULL);
63 }
64
_Locale_codecvt_create(const char * nm,struct _Locale_name_hint * hint,int * __err_code)65 struct _Locale_codecvt *_Locale_codecvt_create(const char *nm, struct _Locale_name_hint* hint,
66 int *__err_code) {
67 // Glibc do not support multibyte manipulation for the moment, it simply implements "C".
68 if (nm[0] == 'C' && nm[1] == 0)
69 { return (struct _Locale_codecvt*)0x01; }
70 *__err_code = _STLP_LOC_NO_PLATFORM_SUPPORT; return 0;
71 }
72
_Locale_numeric_create(const char * nm,struct _Locale_name_hint * hint,int * __err_code)73 struct _Locale_numeric *_Locale_numeric_create(const char *nm, struct _Locale_name_hint* hint,
74 int *__err_code) {
75 *__err_code = _STLP_LOC_UNKNOWN_NAME;
76 return (struct _Locale_numeric*)newlocale(LC_NUMERIC_MASK, nm, NULL);
77 }
78
_Locale_time_create(const char * nm,struct _Locale_name_hint * hint,int * __err_code)79 struct _Locale_time *_Locale_time_create(const char *nm, struct _Locale_name_hint* hint,
80 int *__err_code) {
81 *__err_code = _STLP_LOC_UNKNOWN_NAME;
82 return (struct _Locale_time*)newlocale(LC_TIME_MASK, nm, NULL);
83 }
84
_Locale_collate_create(const char * nm,struct _Locale_name_hint * hint,int * __err_code)85 struct _Locale_collate *_Locale_collate_create(const char *nm, struct _Locale_name_hint* hint,
86 int *__err_code) {
87 *__err_code = _STLP_LOC_UNKNOWN_NAME;
88 return (struct _Locale_collate*)newlocale(LC_COLLATE_MASK, nm, NULL);
89 }
90
_Locale_monetary_create(const char * nm,struct _Locale_name_hint * hint,int * __err_code)91 struct _Locale_monetary *_Locale_monetary_create(const char *nm, struct _Locale_name_hint* hint,
92 int *__err_code) {
93 *__err_code = _STLP_LOC_UNKNOWN_NAME;
94 return (struct _Locale_monetary*)newlocale(LC_MONETARY_MASK, nm, NULL);
95 }
96
_Locale_messages_create(const char * nm,struct _Locale_name_hint * hint,int * __err_code)97 struct _Locale_messages *_Locale_messages_create(const char *nm, struct _Locale_name_hint* hint,
98 int *__err_code) {
99 *__err_code = _STLP_LOC_UNKNOWN_NAME;
100 return (struct _Locale_messages*)newlocale(LC_MESSAGES_MASK, nm, NULL);
101 }
102
103 /*
104 try to see locale category LC should be used from environment;
105 according POSIX, the order is
106 1. LC_ALL
107 2. category (LC_CTYPE, LC_NUMERIC, ... )
108 3. LANG
109 If set nothing, return "C" (this really implementation-specific).
110 */
_Locale_aux_default(const char * LC,char * nm)111 static const char *_Locale_aux_default( const char *LC, char *nm )
112 {
113 char *name = getenv( "LC_ALL" );
114
115 if ( name != NULL && *name != 0 ) {
116 return name;
117 }
118 name = getenv( LC );
119 if ( name != NULL && *name != 0 ) {
120 return name;
121 }
122 name = getenv( "LANG" );
123 if ( name != NULL && *name != 0 ) {
124 return name;
125 }
126
127 return _C_name;
128 }
129
_Locale_ctype_default(char * nm)130 const char *_Locale_ctype_default( char *nm )
131 {
132 return _Locale_aux_default( "LC_CTYPE", nm );
133 }
134
_Locale_numeric_default(char * nm)135 const char *_Locale_numeric_default( char *nm )
136 {
137 return _Locale_aux_default( "LC_NUMERIC", nm );
138 }
139
_Locale_time_default(char * nm)140 const char *_Locale_time_default( char *nm )
141 {
142 return _Locale_aux_default( "LC_TIME", nm );
143 }
144
_Locale_collate_default(char * nm)145 const char *_Locale_collate_default( char *nm )
146 {
147 return _Locale_aux_default( "LC_COLLATE", nm );
148 }
149
_Locale_monetary_default(char * nm)150 const char *_Locale_monetary_default( char *nm )
151 {
152 return _Locale_aux_default( "LC_MONETARY", nm );
153 }
154
_Locale_messages_default(char * nm)155 const char *_Locale_messages_default( char *nm )
156 {
157 return _Locale_aux_default( "LC_MESSAGES", nm );
158 }
159
_Locale_ctype_name(const struct _Locale_ctype * __loc,char * buf)160 char const*_Locale_ctype_name( const struct _Locale_ctype *__loc, char *buf )
161 {
162 return ((locale_t)__loc)->__names[LC_CTYPE];
163 }
164
_Locale_codecvt_name(const struct _Locale_codecvt * __loc,char * buf)165 char const*_Locale_codecvt_name( const struct _Locale_codecvt *__loc, char *buf )
166 {
167 return _C_name;
168 }
169
_Locale_numeric_name(const struct _Locale_numeric * __loc,char * buf)170 char const*_Locale_numeric_name( const struct _Locale_numeric *__loc, char *buf )
171 {
172 return ((locale_t)__loc)->__names[LC_NUMERIC];
173 }
174
_Locale_time_name(const struct _Locale_time * __loc,char * buf)175 char const*_Locale_time_name( const struct _Locale_time *__loc, char *buf )
176 {
177 return ((locale_t)__loc)->__names[LC_TIME];
178 }
179
_Locale_collate_name(const struct _Locale_collate * __loc,char * buf)180 char const*_Locale_collate_name( const struct _Locale_collate *__loc, char *buf )
181 {
182 return ((locale_t)__loc)->__names[LC_COLLATE];
183 }
184
_Locale_monetary_name(const struct _Locale_monetary * __loc,char * buf)185 char const*_Locale_monetary_name( const struct _Locale_monetary *__loc, char *buf )
186 {
187 return ((locale_t)__loc)->__names[LC_MONETARY];
188 }
189
_Locale_messages_name(const struct _Locale_messages * __loc,char * buf)190 char const*_Locale_messages_name( const struct _Locale_messages *__loc, char *buf )
191 {
192 return ((locale_t)__loc)->__names[LC_MESSAGES];
193 }
194
_Locale_ctype_destroy(struct _Locale_ctype * __loc)195 void _Locale_ctype_destroy( struct _Locale_ctype *__loc )
196 { freelocale((locale_t)__loc); }
197
_Locale_codecvt_destroy(struct _Locale_codecvt * __loc)198 void _Locale_codecvt_destroy( struct _Locale_codecvt *__loc )
199 {}
200
_Locale_numeric_destroy(struct _Locale_numeric * __loc)201 void _Locale_numeric_destroy( struct _Locale_numeric *__loc )
202 { freelocale((locale_t)__loc); }
203
_Locale_time_destroy(struct _Locale_time * __loc)204 void _Locale_time_destroy( struct _Locale_time *__loc )
205 { freelocale((locale_t)__loc); }
206
_Locale_collate_destroy(struct _Locale_collate * __loc)207 void _Locale_collate_destroy( struct _Locale_collate *__loc )
208 { freelocale((locale_t)__loc); }
209
_Locale_monetary_destroy(struct _Locale_monetary * __loc)210 void _Locale_monetary_destroy( struct _Locale_monetary *__loc )
211 { freelocale((locale_t)__loc); }
212
_Locale_messages_destroy(struct _Locale_messages * __loc)213 void _Locale_messages_destroy( struct _Locale_messages* __loc )
214 { freelocale((locale_t)__loc); }
215
216 /*
217 * locale loc expected either locale name indeed (platform-specific)
218 * or string like "LC_CTYPE=LocaleNameForCType;LC_NUMERIC=LocaleNameForNum;"
219 *
220 */
221
__Extract_locale_name(const char * loc,const char * category,char * buf)222 static char const*__Extract_locale_name( const char *loc, const char *category, char *buf )
223 {
224 char *expr;
225 size_t len_name;
226
227 if( loc[0]=='L' && loc[1]=='C' && loc[2]=='_') {
228 expr = strstr( (char*)loc, category );
229 if ( expr == NULL )
230 return NULL; /* Category not found. */
231 ++expr;
232 len_name = strcspn( expr, ";" );
233 len_name = len_name >= _Locale_MAX_SIMPLE_NAME ? _Locale_MAX_SIMPLE_NAME - 1 : len_name;
234 strncpy( buf, expr, len_name );
235 buf[len_name] = 0;
236 return buf;
237 }
238 return loc;
239 }
240
_Locale_extract_ctype_name(const char * loc,char * buf,struct _Locale_name_hint * hint,int * __err_code)241 char const*_Locale_extract_ctype_name(const char *loc, char *buf,
242 struct _Locale_name_hint* hint, int *__err_code)
243 { return __Extract_locale_name( loc, "LC_CTYPE=", buf ); }
244
_Locale_extract_numeric_name(const char * loc,char * buf,struct _Locale_name_hint * hint,int * __err_code)245 char const*_Locale_extract_numeric_name(const char *loc, char *buf,
246 struct _Locale_name_hint* hint, int *__err_code)
247 { return __Extract_locale_name( loc, "LC_NUMERIC=", buf ); }
248
_Locale_extract_time_name(const char * loc,char * buf,struct _Locale_name_hint * hint,int * __err_code)249 char const*_Locale_extract_time_name(const char *loc, char *buf,
250 struct _Locale_name_hint* hint, int *__err_code)
251 { return __Extract_locale_name( loc, "LC_TIME=", buf ); }
252
_Locale_extract_collate_name(const char * loc,char * buf,struct _Locale_name_hint * hint,int * __err_code)253 char const*_Locale_extract_collate_name(const char *loc, char *buf,
254 struct _Locale_name_hint* hint, int *__err_code)
255 { return __Extract_locale_name( loc, "LC_COLLATE=", buf ); }
256
_Locale_extract_monetary_name(const char * loc,char * buf,struct _Locale_name_hint * hint,int * __err_code)257 char const*_Locale_extract_monetary_name(const char *loc, char *buf,
258 struct _Locale_name_hint* hint, int *__err_code)
259 { return __Extract_locale_name( loc, "LC_MONETARY=", buf ); }
260
_Locale_extract_messages_name(const char * loc,char * buf,struct _Locale_name_hint * hint,int * __err_code)261 char const*_Locale_extract_messages_name(const char *loc, char *buf,
262 struct _Locale_name_hint* hint, int *__err_code)
263 { return __Extract_locale_name( loc, "LC_MESSAGES=", buf ); }
264
_Locale_get_ctype_hint(struct _Locale_ctype * ctype)265 struct _Locale_name_hint* _Locale_get_ctype_hint(struct _Locale_ctype* ctype)
266 { return 0; }
_Locale_get_numeric_hint(struct _Locale_numeric * numeric)267 struct _Locale_name_hint* _Locale_get_numeric_hint(struct _Locale_numeric* numeric)
268 { return 0; }
_Locale_get_time_hint(struct _Locale_time * time)269 struct _Locale_name_hint* _Locale_get_time_hint(struct _Locale_time* time)
270 { return 0; }
_Locale_get_collate_hint(struct _Locale_collate * collate)271 struct _Locale_name_hint* _Locale_get_collate_hint(struct _Locale_collate* collate)
272 { return 0; }
_Locale_get_monetary_hint(struct _Locale_monetary * monetary)273 struct _Locale_name_hint* _Locale_get_monetary_hint(struct _Locale_monetary* monetary)
274 { return 0; }
_Locale_get_messages_hint(struct _Locale_messages * messages)275 struct _Locale_name_hint* _Locale_get_messages_hint(struct _Locale_messages* messages)
276 { return 0; }
277
278 /* ctype */
279
_Locale_ctype_table(struct _Locale_ctype * __loc)280 const _Locale_mask_t *_Locale_ctype_table( struct _Locale_ctype *__loc )
281 {
282 /* return table with masks (upper, lower, alpha, etc.) */
283 _STLP_STATIC_ASSERT( sizeof(_Locale_mask_t) == sizeof(((locale_t)__loc)->__ctype_b[0]) )
284 return ((locale_t)__loc)->__ctype_b;
285 }
286
_Locale_toupper(struct _Locale_ctype * __loc,int c)287 int _Locale_toupper( struct _Locale_ctype *__loc, int c )
288 { return ((locale_t)__loc)->__ctype_toupper[c]; }
289
_Locale_tolower(struct _Locale_ctype * __loc,int c)290 int _Locale_tolower( struct _Locale_ctype *__loc, int c )
291 { return ((locale_t)__loc)->__ctype_tolower[c]; }
292
293 #if !defined (_STLP_NO_WCHAR_T)
_WLocale_ctype(struct _Locale_ctype * __loc,wint_t wc,_Locale_mask_t __mask)294 _Locale_mask_t _WLocale_ctype( struct _Locale_ctype *__loc, wint_t wc, _Locale_mask_t __mask )
295 {
296 _Locale_mask_t ret = 0;
297 if ((__mask & _Locale_ALPHA) != 0 && iswalpha_l(wc, (locale_t)__loc))
298 ret |= _Locale_ALPHA;
299
300 if ((__mask & _Locale_CNTRL) != 0 && iswcntrl_l(wc, (locale_t)__loc))
301 ret |= _Locale_CNTRL;
302
303 if ((__mask & _Locale_DIGIT) != 0 && iswdigit_l(wc, (locale_t)__loc))
304 ret |= _Locale_DIGIT;
305
306 if ((__mask & _Locale_PRINT) != 0 && iswprint_l(wc, (locale_t)__loc))
307 ret |= _Locale_PRINT;
308
309 if ((__mask & _Locale_PUNCT) != 0 && iswpunct_l(wc, (locale_t)__loc))
310 ret |= _Locale_PUNCT;
311
312 if ((__mask & _Locale_SPACE) != 0 && iswspace_l(wc, (locale_t)__loc))
313 ret |= _Locale_SPACE;
314
315 if ((__mask & _Locale_XDIGIT) != 0 && iswxdigit_l(wc, (locale_t)__loc))
316 ret |= _Locale_XDIGIT;
317
318 if ((__mask & _Locale_UPPER) != 0 && iswupper_l(wc, (locale_t)__loc))
319 ret |= _Locale_UPPER;
320
321 if ((__mask & _Locale_LOWER) != 0 && iswlower_l(wc, (locale_t)__loc))
322 ret |= _Locale_LOWER;
323
324 return ret;
325 }
326
_WLocale_tolower(struct _Locale_ctype * __loc,wint_t c)327 wint_t _WLocale_tolower( struct _Locale_ctype *__loc, wint_t c )
328 {
329 return towlower_l( c, ((locale_t)__loc) );
330 }
331
_WLocale_toupper(struct _Locale_ctype * __loc,wint_t c)332 wint_t _WLocale_toupper( struct _Locale_ctype *__loc, wint_t c )
333 {
334 return towupper_l( c, ((locale_t)__loc) );
335 }
336 #endif
337
_WLocale_mb_cur_max(struct _Locale_codecvt * lcodecvt)338 int _WLocale_mb_cur_max( struct _Locale_codecvt * lcodecvt) { return 1; }
_WLocale_mb_cur_min(struct _Locale_codecvt * lcodecvt)339 int _WLocale_mb_cur_min( struct _Locale_codecvt * lcodecvt) { return 1; }
_WLocale_is_stateless(struct _Locale_codecvt * lcodecvt)340 int _WLocale_is_stateless( struct _Locale_codecvt * lcodecvt) { return 1; }
341
342 #if !defined (_STLP_NO_WCHAR_T)
_WLocale_mbtowc(struct _Locale_codecvt * lcodecvt,wchar_t * to,const char * from,size_t n,mbstate_t * st)343 size_t _WLocale_mbtowc(struct _Locale_codecvt *lcodecvt,
344 wchar_t *to,
345 const char *from, size_t n,
346 mbstate_t *st)
347 { *to = *from; return 1; }
348
_WLocale_wctomb(struct _Locale_codecvt * lcodecvt,char * to,size_t n,const wchar_t c,mbstate_t * st)349 size_t _WLocale_wctomb(struct _Locale_codecvt *lcodecvt,
350 char *to, size_t n,
351 const wchar_t c,
352 mbstate_t *st)
353 { *to = (char)c; return 1; }
354 #endif
355
_WLocale_unshift(struct _Locale_codecvt * lcodecvt,mbstate_t * st,char * buf,size_t n,char ** next)356 size_t _WLocale_unshift(struct _Locale_codecvt *lcodecvt,
357 mbstate_t *st,
358 char *buf, size_t n, char ** next)
359 { *next = buf; return 0; }
360
361 /* Collate */
_Locale_strcmp(struct _Locale_collate * __loc,const char * s1,size_t n1,const char * s2,size_t n2)362 int _Locale_strcmp(struct _Locale_collate * __loc,
363 const char *s1, size_t n1,
364 const char *s2, size_t n2) {
365 int ret = 0;
366 char buf1[64], buf2[64];
367 while (n1 > 0 || n2 > 0) {
368 size_t bufsize1 = n1 < 63 ? n1 : 63;
369 size_t bufsize2 = n2 < 63 ? n2 : 63;
370 strncpy(buf1, s1, bufsize1); buf1[bufsize1] = 0;
371 strncpy(buf2, s2, bufsize2); buf2[bufsize2] = 0;
372
373 ret = strcoll_l(buf1, buf2, (locale_t)__loc);
374 if (ret != 0) return ret;
375 s1 += bufsize1; n1 -= bufsize1;
376 s2 += bufsize2; n2 -= bufsize2;
377 }
378 return ret;
379 }
380
381 #if !defined (_STLP_NO_WCHAR_T)
_WLocale_strcmp(struct _Locale_collate * __loc,const wchar_t * s1,size_t n1,const wchar_t * s2,size_t n2)382 int _WLocale_strcmp(struct _Locale_collate *__loc,
383 const wchar_t *s1, size_t n1,
384 const wchar_t *s2, size_t n2) {
385 int ret = 0;
386 wchar_t buf1[64], buf2[64];
387 while (n1 > 0 || n2 > 0) {
388 size_t bufsize1 = n1 < 63 ? n1 : 63;
389 size_t bufsize2 = n2 < 63 ? n2 : 63;
390 wcsncpy(buf1, s1, bufsize1); buf1[bufsize1] = 0;
391 wcsncpy(buf2, s2, bufsize2); buf2[bufsize2] = 0;
392
393 ret = wcscoll_l(buf1, buf2, (locale_t)__loc);
394 if (ret != 0) return ret;
395 s1 += bufsize1; n1 -= bufsize1;
396 s2 += bufsize2; n2 -= bufsize2;
397 }
398 return ret;
399 }
400
401 #endif
402
_Locale_strxfrm(struct _Locale_collate * __loc,char * dest,size_t dest_n,const char * src,size_t src_n)403 size_t _Locale_strxfrm(struct _Locale_collate *__loc,
404 char *dest, size_t dest_n,
405 const char *src, size_t src_n )
406 {
407 const char *real_src;
408 char *buf = NULL;
409 size_t result;
410
411 if (src_n == 0)
412 {
413 if (dest != NULL) dest[0] = 0;
414 return 0;
415 }
416 if (src[src_n] != 0) {
417 buf = malloc(src_n + 1);
418 strncpy(buf, src, src_n);
419 buf[src_n] = 0;
420 real_src = buf;
421 }
422 else
423 real_src = src;
424 result = strxfrm_l(dest, real_src, dest_n, (locale_t)__loc);
425 if (buf != NULL) free(buf);
426 return result;
427 }
428
429 # ifndef _STLP_NO_WCHAR_T
430
_WLocale_strxfrm(struct _Locale_collate * __loc,wchar_t * dest,size_t dest_n,const wchar_t * src,size_t src_n)431 size_t _WLocale_strxfrm( struct _Locale_collate *__loc,
432 wchar_t *dest, size_t dest_n,
433 const wchar_t *src, size_t src_n )
434 {
435 const wchar_t *real_src;
436 wchar_t *buf = NULL;
437 size_t result;
438
439 if (src_n == 0)
440 {
441 if (dest != NULL) dest[0] = 0;
442 return 0;
443 }
444 if (src[src_n] != 0) {
445 buf = malloc((src_n + 1) * sizeof(wchar_t));
446 wcsncpy(buf, src, src_n);
447 buf[src_n] = 0;
448 real_src = buf;
449 }
450 else
451 real_src = src;
452 result = wcsxfrm_l(dest, real_src, dest_n, (locale_t)__loc);
453 if (buf != NULL) free(buf);
454 return result;
455 }
456
457 # endif
458
459 /* Numeric */
460
_Locale_decimal_point(struct _Locale_numeric * __loc)461 char _Locale_decimal_point(struct _Locale_numeric *__loc)
462 {
463 return *(nl_langinfo_l(RADIXCHAR, (locale_t)__loc));
464 }
465
_Locale_thousands_sep(struct _Locale_numeric * __loc)466 char _Locale_thousands_sep(struct _Locale_numeric *__loc)
467 {
468 return *(nl_langinfo_l(THOUSEP, (locale_t)__loc));
469 }
470
_Locale_grouping(struct _Locale_numeric * __loc)471 const char* _Locale_grouping(struct _Locale_numeric *__loc)
472 {
473 return (_Locale_thousands_sep(__loc) != 0 ) ? (nl_langinfo_l(GROUPING, (locale_t)__loc)) : _empty_str;
474 }
475
_Locale_true(struct _Locale_numeric * __loc)476 const char *_Locale_true(struct _Locale_numeric *__loc)
477 {
478 return nl_langinfo_l(YESSTR, (locale_t)__loc);
479 }
480
_Locale_false(struct _Locale_numeric * __loc)481 const char *_Locale_false(struct _Locale_numeric *__loc)
482 {
483 return nl_langinfo_l(NOSTR, (locale_t)__loc);
484 }
485
486 #ifndef _STLP_NO_WCHAR_T
_WLocale_decimal_point(struct _Locale_numeric * __loc)487 wchar_t _WLocale_decimal_point(struct _Locale_numeric *__loc)
488 { return (wchar_t)_Locale_decimal_point(__loc); }
_WLocale_thousands_sep(struct _Locale_numeric * __loc)489 wchar_t _WLocale_thousands_sep(struct _Locale_numeric *__loc)
490 { return (wchar_t)_Locale_thousands_sep(__loc); }
_WLocale_true(struct _Locale_numeric * __loc,wchar_t * buf,size_t bufSize)491 const wchar_t *_WLocale_true(struct _Locale_numeric *__loc, wchar_t *buf, size_t bufSize)
492 { return _ToWChar(_Locale_true(__loc), buf, bufSize); }
_WLocale_false(struct _Locale_numeric * __loc,wchar_t * buf,size_t bufSize)493 const wchar_t *_WLocale_false(struct _Locale_numeric *__loc, wchar_t *buf, size_t bufSize)
494 { return _ToWChar(_Locale_false(__loc), buf, bufSize); }
495 #endif
496
497 /* Monetary */
498
_Locale_int_curr_symbol(struct _Locale_monetary * __loc)499 const char *_Locale_int_curr_symbol(struct _Locale_monetary *__loc)
500 {
501 return nl_langinfo_l(INT_CURR_SYMBOL, (locale_t)__loc);
502 }
503
_Locale_currency_symbol(struct _Locale_monetary * __loc)504 const char *_Locale_currency_symbol(struct _Locale_monetary *__loc)
505 {
506 return nl_langinfo_l(CURRENCY_SYMBOL, (locale_t)__loc);
507 }
508
_Locale_mon_decimal_point(struct _Locale_monetary * __loc)509 char _Locale_mon_decimal_point(struct _Locale_monetary * __loc)
510 {
511 return *(nl_langinfo_l(MON_DECIMAL_POINT,(locale_t)__loc));
512 }
513
_Locale_mon_thousands_sep(struct _Locale_monetary * __loc)514 char _Locale_mon_thousands_sep(struct _Locale_monetary *__loc)
515 {
516 return *(nl_langinfo_l(MON_THOUSANDS_SEP, (locale_t)__loc));
517 }
518
519 #ifndef _STLP_NO_WCHAR_T
_WLocale_int_curr_symbol(struct _Locale_monetary * __loc,wchar_t * buf,size_t bufSize)520 const wchar_t *_WLocale_int_curr_symbol(struct _Locale_monetary *__loc, wchar_t *buf, size_t bufSize)
521 { return _ToWChar(_Locale_int_curr_symbol(__loc), buf, bufSize); }
_WLocale_currency_symbol(struct _Locale_monetary * __loc,wchar_t * buf,size_t bufSize)522 const wchar_t *_WLocale_currency_symbol(struct _Locale_monetary *__loc, wchar_t *buf, size_t bufSize)
523 { return _ToWChar(_Locale_currency_symbol(__loc), buf, bufSize); }
_WLocale_mon_decimal_point(struct _Locale_monetary * __loc)524 wchar_t _WLocale_mon_decimal_point(struct _Locale_monetary * __loc)
525 { return (wchar_t)_Locale_mon_decimal_point(__loc); }
_WLocale_mon_thousands_sep(struct _Locale_monetary * __loc)526 wchar_t _WLocale_mon_thousands_sep(struct _Locale_monetary * __loc)
527 { return (wchar_t)_Locale_mon_thousands_sep(__loc); }
_WLocale_positive_sign(struct _Locale_monetary * __loc,wchar_t * buf,size_t bufSize)528 const wchar_t *_WLocale_positive_sign(struct _Locale_monetary *__loc, wchar_t *buf, size_t bufSize)
529 { return _ToWChar(_Locale_positive_sign(__loc), buf, bufSize); }
_WLocale_negative_sign(struct _Locale_monetary * __loc,wchar_t * buf,size_t bufSize)530 const wchar_t *_WLocale_negative_sign(struct _Locale_monetary *__loc, wchar_t *buf, size_t bufSize)
531 { return _ToWChar(_Locale_negative_sign(__loc), buf, bufSize); }
532 #endif
533
_Locale_mon_grouping(struct _Locale_monetary * __loc)534 const char *_Locale_mon_grouping(struct _Locale_monetary *__loc)
535 {
536 return (_Locale_mon_thousands_sep( __loc ) != 0 ) ? nl_langinfo_l(MON_GROUPING, (locale_t)__loc) : _empty_str;
537 }
538
_Locale_positive_sign(struct _Locale_monetary * __loc)539 const char *_Locale_positive_sign(struct _Locale_monetary *__loc)
540 {
541 return nl_langinfo_l(POSITIVE_SIGN, (locale_t)__loc);
542 }
543
_Locale_negative_sign(struct _Locale_monetary * __loc)544 const char *_Locale_negative_sign(struct _Locale_monetary *__loc)
545 {
546 return nl_langinfo_l(NEGATIVE_SIGN, (locale_t)__loc);
547 }
548
_Locale_int_frac_digits(struct _Locale_monetary * __loc)549 char _Locale_int_frac_digits(struct _Locale_monetary *__loc)
550 {
551 /* We are forced to manually handled the "C" locale for consistency with
552 * the default implementation in STLport. */
553 const char* lname = ((locale_t)__loc)->__names[LC_MONETARY];
554 if (lname[0] == 'C' && lname[1] == 0)
555 return 0;
556 return *(nl_langinfo_l(INT_FRAC_DIGITS, (locale_t)__loc));
557 }
558
_Locale_frac_digits(struct _Locale_monetary * __loc)559 char _Locale_frac_digits(struct _Locale_monetary *__loc)
560 {
561 /* We are forced to manually handled the "C" locale for consistency with
562 * the default implementation in STLport. */
563 const char* lname = ((locale_t)__loc)->__names[LC_MONETARY];
564 if (lname[0] == 'C' && lname[1] == 0)
565 return 0;
566 return *(nl_langinfo_l(FRAC_DIGITS, (locale_t)__loc));
567 }
568
569 /* 1 if currency_symbol precedes a positive value, 0 if succeeds */
_Locale_p_cs_precedes(struct _Locale_monetary * __loc)570 int _Locale_p_cs_precedes(struct _Locale_monetary *__loc)
571 {
572 return *(nl_langinfo_l(P_CS_PRECEDES, (locale_t)__loc));
573 }
574
575 /* 1 if a space separates currency_symbol from a positive value. */
_Locale_p_sep_by_space(struct _Locale_monetary * __loc)576 int _Locale_p_sep_by_space(struct _Locale_monetary *__loc)
577 {
578 return *(nl_langinfo_l(P_SEP_BY_SPACE, (locale_t)__loc));
579 }
580
581 /*
582 * 0 Parentheses surround the quantity and currency_symbol
583 * 1 The sign string precedes the quantity and currency_symbol
584 * 2 The sign string succeeds the quantity and currency_symbol.
585 * 3 The sign string immediately precedes the currency_symbol.
586 * 4 The sign string immediately succeeds the currency_symbol.
587 */
_Locale_p_sign_posn(struct _Locale_monetary * __loc)588 int _Locale_p_sign_posn(struct _Locale_monetary *__loc)
589 {
590 return *(nl_langinfo_l(P_SIGN_POSN, (locale_t)__loc));
591 }
592
593 /* 1 if currency_symbol precedes a negative value, 0 if succeeds */
_Locale_n_cs_precedes(struct _Locale_monetary * __loc)594 int _Locale_n_cs_precedes(struct _Locale_monetary *__loc)
595 {
596 return *(nl_langinfo_l(N_CS_PRECEDES, (locale_t)__loc));
597 }
598
599 /* 1 if a space separates currency_symbol from a negative value. */
_Locale_n_sep_by_space(struct _Locale_monetary * __loc)600 int _Locale_n_sep_by_space(struct _Locale_monetary *__loc)
601 {
602 return *(nl_langinfo_l(N_SEP_BY_SPACE, (locale_t)__loc));
603 }
604
605 /*
606 * 0 Parentheses surround the quantity and currency_symbol
607 * 1 The sign string precedes the quantity and currency_symbol
608 * 2 The sign string succeeds the quantity and currency_symbol.
609 * 3 The sign string immediately precedes the currency_symbol.
610 * 4 The sign string immediately succeeds the currency_symbol.
611 */
_Locale_n_sign_posn(struct _Locale_monetary * __loc)612 int _Locale_n_sign_posn(struct _Locale_monetary *__loc)
613 {
614 return *(nl_langinfo_l(N_SIGN_POSN, (locale_t)__loc));
615 }
616
617
618 /* Time */
_Locale_full_monthname(struct _Locale_time * __loc,int _m)619 const char *_Locale_full_monthname(struct _Locale_time *__loc, int _m )
620 {
621 return nl_langinfo_l(MON_1 + _m, (locale_t)__loc);
622 }
623
_Locale_abbrev_monthname(struct _Locale_time * __loc,int _m)624 const char *_Locale_abbrev_monthname(struct _Locale_time *__loc, int _m )
625 {
626 return nl_langinfo_l(ABMON_1 + _m, (locale_t)__loc);
627 }
628
_Locale_full_dayofweek(struct _Locale_time * __loc,int _d)629 const char *_Locale_full_dayofweek(struct _Locale_time *__loc, int _d )
630 {
631 return nl_langinfo_l(DAY_1 + _d, (locale_t)__loc);
632 }
633
_Locale_abbrev_dayofweek(struct _Locale_time * __loc,int _d)634 const char *_Locale_abbrev_dayofweek(struct _Locale_time *__loc, int _d )
635 {
636 return nl_langinfo_l(ABDAY_1 + _d, (locale_t)__loc);
637 }
638
_Locale_d_t_fmt(struct _Locale_time * __loc)639 const char *_Locale_d_t_fmt(struct _Locale_time *__loc)
640 {
641 return nl_langinfo_l(D_T_FMT, (locale_t)__loc);
642 }
643
_Locale_d_fmt(struct _Locale_time * __loc)644 const char *_Locale_d_fmt(struct _Locale_time *__loc )
645 {
646 return nl_langinfo_l(D_FMT, (locale_t)__loc);
647 }
648
_Locale_t_fmt(struct _Locale_time * __loc)649 const char *_Locale_t_fmt(struct _Locale_time *__loc )
650 {
651 return nl_langinfo_l(T_FMT, (locale_t)__loc);
652 }
653
_Locale_long_d_t_fmt(struct _Locale_time * __loc)654 const char *_Locale_long_d_t_fmt(struct _Locale_time *__loc )
655 {
656 return nl_langinfo_l(ERA_D_T_FMT, (locale_t)__loc);
657 }
658
_Locale_long_d_fmt(struct _Locale_time * __loc)659 const char *_Locale_long_d_fmt(struct _Locale_time *__loc )
660 {
661 return nl_langinfo_l(ERA_D_FMT, (locale_t)__loc);
662 }
663
_Locale_am_str(struct _Locale_time * __loc)664 const char *_Locale_am_str(struct _Locale_time *__loc )
665 {
666 return nl_langinfo_l(AM_STR, (locale_t)__loc);
667 }
668
_Locale_pm_str(struct _Locale_time * __loc)669 const char *_Locale_pm_str(struct _Locale_time* __loc )
670 {
671 return nl_langinfo_l(PM_STR, (locale_t)__loc);
672 }
673
674 #ifndef _STLP_NO_WCHAR_T
_WLocale_full_monthname(struct _Locale_time * __loc,int _m,wchar_t * buf,size_t bufSize)675 const wchar_t *_WLocale_full_monthname(struct _Locale_time *__loc, int _m, wchar_t *buf, size_t bufSize)
676 { return _ToWChar(_Locale_full_monthname(__loc, _m), buf, bufSize); }
_WLocale_abbrev_monthname(struct _Locale_time * __loc,int _m,wchar_t * buf,size_t bufSize)677 const wchar_t *_WLocale_abbrev_monthname(struct _Locale_time *__loc, int _m, wchar_t *buf, size_t bufSize)
678 { return _ToWChar(_Locale_abbrev_monthname(__loc, _m), buf, bufSize); }
_WLocale_full_dayofweek(struct _Locale_time * __loc,int _d,wchar_t * buf,size_t bufSize)679 const wchar_t *_WLocale_full_dayofweek(struct _Locale_time *__loc, int _d, wchar_t *buf, size_t bufSize)
680 { return _ToWChar(_Locale_full_dayofweek(__loc, _d), buf, bufSize); }
_WLocale_abbrev_dayofweek(struct _Locale_time * __loc,int _d,wchar_t * buf,size_t bufSize)681 const wchar_t *_WLocale_abbrev_dayofweek(struct _Locale_time *__loc, int _d, wchar_t *buf, size_t bufSize)
682 { return _ToWChar(_Locale_abbrev_dayofweek(__loc, _d), buf, bufSize); }
_WLocale_am_str(struct _Locale_time * __loc,wchar_t * buf,size_t bufSize)683 const wchar_t *_WLocale_am_str(struct _Locale_time *__loc, wchar_t *buf, size_t bufSize)
684 { return _ToWChar(_Locale_am_str(__loc), buf, bufSize); }
_WLocale_pm_str(struct _Locale_time * __loc,wchar_t * buf,size_t bufSize)685 const wchar_t *_WLocale_pm_str(struct _Locale_time* __loc, wchar_t *buf, size_t bufSize)
686 { return _ToWChar(_Locale_pm_str(__loc), buf, bufSize); }
687 #endif
688
689 /* Messages */
690
_Locale_catopen(struct _Locale_messages * __loc,const char * __cat_name)691 nl_catd_type _Locale_catopen(struct _Locale_messages *__loc, const char *__cat_name )
692 {
693 return catopen( __cat_name, NL_CAT_LOCALE );
694 }
695
_Locale_catclose(struct _Locale_messages * __loc,nl_catd_type __cat)696 void _Locale_catclose(struct _Locale_messages *__loc, nl_catd_type __cat )
697 {
698 catclose( __cat );
699 }
700
_Locale_catgets(struct _Locale_messages * __loc,nl_catd_type __cat,int __setid,int __msgid,const char * dfault)701 const char *_Locale_catgets(struct _Locale_messages *__loc, nl_catd_type __cat,
702 int __setid, int __msgid, const char *dfault)
703 {
704 return catgets( __cat, __setid, __msgid, dfault );
705 }
706