xlocale.h 5.6 KB

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