c_locale_glibc2.c 21 KB

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