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