xlocale.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. // -*- C++ -*-
  2. //===--------------------- support/ibm/xlocale.h -------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_SUPPORT_IBM_XLOCALE_H
  11. #define _LIBCPP_SUPPORT_IBM_XLOCALE_H
  12. #include <support/ibm/locale_mgmt_aix.h>
  13. #if defined(_AIX)
  14. #include "cstdlib"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #if !defined(_AIX71)
  19. // AIX 7.1 and higher has these definitions. Definitions and stubs
  20. // are provied here as a temporary workaround on AIX 6.1.
  21. static inline
  22. int isalnum_l(int c, locale_t locale)
  23. {
  24. return __xisalnum(locale, c);
  25. }
  26. static inline
  27. int isalpha_l(int c, locale_t locale)
  28. {
  29. return __xisalpha(locale, c);
  30. }
  31. static inline
  32. int isblank_l(int c, locale_t locale)
  33. {
  34. return __xisblank(locale, c);
  35. }
  36. static inline
  37. int iscntrl_l(int c, locale_t locale)
  38. {
  39. return __xiscntrl(locale, c);
  40. }
  41. static inline
  42. int isdigit_l(int c, locale_t locale)
  43. {
  44. return __xisdigit(locale, c);
  45. }
  46. static inline
  47. int isgraph_l(int c, locale_t locale)
  48. {
  49. return __xisgraph(locale, c);
  50. }
  51. static inline
  52. int islower_l(int c, locale_t locale)
  53. {
  54. return __xislower(locale, c);
  55. }
  56. static inline
  57. int isprint_l(int c, locale_t locale)
  58. {
  59. return __xisprint(locale, c);
  60. }
  61. static inline
  62. int ispunct_l(int c, locale_t locale)
  63. {
  64. return __xispunct(locale, c);
  65. }
  66. static inline
  67. int isspace_l(int c, locale_t locale)
  68. {
  69. return __xisspace(locale, c);
  70. }
  71. static inline
  72. int isupper_l(int c, locale_t locale)
  73. {
  74. return __xisupper(locale, c);
  75. }
  76. static inline
  77. int isxdigit_l(int c, locale_t locale)
  78. {
  79. return __xisxdigit(locale, c);
  80. }
  81. static inline
  82. int iswalnum_l(wchar_t wc, locale_t locale)
  83. {
  84. return __xiswalnum(locale, wc);
  85. }
  86. static inline
  87. int iswalpha_l(wchar_t wc, locale_t locale)
  88. {
  89. return __xiswalpha(locale, wc);
  90. }
  91. static inline
  92. int iswblank_l(wchar_t wc, locale_t locale)
  93. {
  94. return __xiswblank(locale, wc);
  95. }
  96. static inline
  97. int iswcntrl_l(wchar_t wc, locale_t locale)
  98. {
  99. return __xiswcntrl(locale, wc);
  100. }
  101. static inline
  102. int iswdigit_l(wchar_t wc, locale_t locale)
  103. {
  104. return __xiswdigit(locale, wc);
  105. }
  106. static inline
  107. int iswgraph_l(wchar_t wc, locale_t locale)
  108. {
  109. return __xiswgraph(locale, wc);
  110. }
  111. static inline
  112. int iswlower_l(wchar_t wc, locale_t locale)
  113. {
  114. return __xiswlower(locale, wc);
  115. }
  116. static inline
  117. int iswprint_l(wchar_t wc, locale_t locale)
  118. {
  119. return __xiswprint(locale, wc);
  120. }
  121. static inline
  122. int iswpunct_l(wchar_t wc, locale_t locale)
  123. {
  124. return __xiswpunct(locale, wc);
  125. }
  126. static inline
  127. int iswspace_l(wchar_t wc, locale_t locale)
  128. {
  129. return __xiswspace(locale, wc);
  130. }
  131. static inline
  132. int iswupper_l(wchar_t wc, locale_t locale)
  133. {
  134. return __xiswupper(locale, wc);
  135. }
  136. static inline
  137. int iswxdigit_l(wchar_t wc, locale_t locale)
  138. {
  139. return __xiswxdigit(locale, wc);
  140. }
  141. static inline
  142. int iswctype_l(wint_t wc, wctype_t desc, locale_t locale)
  143. {
  144. return __xiswctype(locale, wc, desc);
  145. }
  146. static inline
  147. int toupper_l(int c, locale_t locale)
  148. {
  149. return __xtoupper(locale, c);
  150. }
  151. static inline
  152. int tolower_l(int c, locale_t locale)
  153. {
  154. return __xtolower(locale, c);
  155. }
  156. static inline
  157. wint_t towupper_l(wint_t wc, locale_t locale)
  158. {
  159. return __xtowupper(locale, wc);
  160. }
  161. static inline
  162. wint_t towlower_l(wint_t wc, locale_t locale)
  163. {
  164. return __xtowlower(locale, wc);
  165. }
  166. static inline
  167. int strcoll_l(const char *__s1, const char *__s2, locale_t locale)
  168. {
  169. return __xstrcoll(locale, __s1, __s2);
  170. }
  171. static inline
  172. int wcscoll_l(const wchar_t *__s1, const wchar_t *__s2, locale_t locale)
  173. {
  174. return __xwcscoll(locale, __s1, __s2);
  175. }
  176. static inline
  177. size_t strxfrm_l(char *__s1, const char *__s2, size_t __n, locale_t locale)
  178. {
  179. return __xstrxfrm(locale, __s1, __s2, __n);
  180. }
  181. static inline
  182. size_t wcsxfrm_l(wchar_t *__ws1, const wchar_t *__ws2, size_t __n,
  183. locale_t locale)
  184. {
  185. return __xwcsxfrm(locale, __ws1, __ws2, __n);
  186. }
  187. #endif // !defined(_AIX71)
  188. // strftime_l() is defined by POSIX. However, AIX 7.1 does not have it
  189. // implemented yet.
  190. static inline
  191. size_t strftime_l(char *__s, size_t __size, const char *__fmt,
  192. const struct tm *__tm, locale_t locale) {
  193. return __xstrftime(locale, __s, __size, __fmt, __tm);
  194. }
  195. // The following are not POSIX routines. These are quick-and-dirty hacks
  196. // to make things pretend to work
  197. static inline
  198. long long strtoll_l(const char *__nptr, char **__endptr,
  199. int __base, locale_t locale) {
  200. return strtoll(__nptr, __endptr, __base);
  201. }
  202. static inline
  203. long strtol_l(const char *__nptr, char **__endptr,
  204. int __base, locale_t locale) {
  205. return strtol(__nptr, __endptr, __base);
  206. }
  207. static inline
  208. long double strtold_l(const char *__nptr, char **__endptr,
  209. locale_t locale) {
  210. return strtold(__nptr, __endptr);
  211. }
  212. static inline
  213. unsigned long long strtoull_l(const char *__nptr, char **__endptr,
  214. int __base, locale_t locale) {
  215. return strtoull(__nptr, __endptr, __base);
  216. }
  217. static inline
  218. unsigned long strtoul_l(const char *__nptr, char **__endptr,
  219. int __base, locale_t locale) {
  220. return strtoul(__nptr, __endptr, __base);
  221. }
  222. static inline
  223. int vasprintf(char **strp, const char *fmt, va_list ap)
  224. {
  225. const size_t buff_size = 256;
  226. int str_size;
  227. if ((*strp = (char *)malloc(buff_size)) == NULL)
  228. {
  229. return -1;
  230. }
  231. if ((str_size = vsnprintf(*strp, buff_size, fmt, ap)) >= buff_size)
  232. {
  233. if ((*strp = (char *)realloc(*strp, str_size + 1)) == NULL)
  234. {
  235. return -1;
  236. }
  237. str_size = vsnprintf(*strp, str_size + 1, fmt, ap);
  238. }
  239. return str_size;
  240. }
  241. #ifdef __cplusplus
  242. }
  243. #endif
  244. #endif // defined(_AIX)
  245. #endif // _LIBCPP_SUPPORT_IBM_XLOCALE_H