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