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
18extern "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.
24static inline
25int isalnum_l(int c, locale_t locale)
26{
27  return __xisalnum(locale, c);
28}
29static inline
30int isalpha_l(int c, locale_t locale)
31{
32  return __xisalpha(locale, c);
33}
34static inline
35int isblank_l(int c, locale_t locale)
36{
37  return __xisblank(locale, c);
38}
39static inline
40int iscntrl_l(int c, locale_t locale)
41{
42  return __xiscntrl(locale, c);
43}
44static inline
45int isdigit_l(int c, locale_t locale)
46{
47  return __xisdigit(locale, c);
48}
49static inline
50int isgraph_l(int c, locale_t locale)
51{
52  return __xisgraph(locale, c);
53}
54static inline
55int islower_l(int c, locale_t locale)
56{
57  return __xislower(locale, c);
58}
59static inline
60int isprint_l(int c, locale_t locale)
61{
62  return __xisprint(locale, c);
63}
64
65static inline
66int ispunct_l(int c, locale_t locale)
67{
68  return __xispunct(locale, c);
69}
70static inline
71int isspace_l(int c, locale_t locale)
72{
73  return __xisspace(locale, c);
74}
75static inline
76int isupper_l(int c, locale_t locale)
77{
78  return __xisupper(locale, c);
79}
80
81static inline
82int isxdigit_l(int c, locale_t locale)
83{
84  return __xisxdigit(locale, c);
85}
86
87static inline
88int iswalnum_l(wchar_t wc, locale_t locale)
89{
90  return __xiswalnum(locale, wc);
91}
92
93static inline
94int iswalpha_l(wchar_t wc, locale_t locale)
95{
96  return __xiswalpha(locale, wc);
97}
98
99static inline
100int iswblank_l(wchar_t wc, locale_t locale)
101{
102  return __xiswblank(locale, wc);
103}
104
105static inline
106int iswcntrl_l(wchar_t wc, locale_t locale)
107{
108  return __xiswcntrl(locale, wc);
109}
110
111static inline
112int iswdigit_l(wchar_t wc, locale_t locale)
113{
114  return __xiswdigit(locale, wc);
115}
116
117static inline
118int iswgraph_l(wchar_t wc, locale_t locale)
119{
120  return __xiswgraph(locale, wc);
121}
122
123static inline
124int iswlower_l(wchar_t wc, locale_t locale)
125{
126  return __xiswlower(locale, wc);
127}
128
129static inline
130int iswprint_l(wchar_t wc, locale_t locale)
131{
132  return __xiswprint(locale, wc);
133}
134
135static inline
136int iswpunct_l(wchar_t wc, locale_t locale)
137{
138  return __xiswpunct(locale, wc);
139}
140
141static inline
142int iswspace_l(wchar_t wc, locale_t locale)
143{
144  return __xiswspace(locale, wc);
145}
146
147static inline
148int iswupper_l(wchar_t wc, locale_t locale)
149{
150  return __xiswupper(locale, wc);
151}
152
153static inline
154int iswxdigit_l(wchar_t wc, locale_t locale)
155{
156  return __xiswxdigit(locale, wc);
157}
158
159static inline
160int iswctype_l(wint_t wc, wctype_t desc, locale_t locale)
161{
162  return __xiswctype(locale, wc, desc);
163}
164
165static inline
166int toupper_l(int c, locale_t locale)
167{
168  return __xtoupper(locale, c);
169}
170static inline
171int tolower_l(int c, locale_t locale)
172{
173  return __xtolower(locale, c);
174}
175static inline
176wint_t towupper_l(wint_t wc, locale_t locale)
177{
178  return __xtowupper(locale, wc);
179}
180static inline
181wint_t towlower_l(wint_t wc, locale_t locale)
182{
183  return __xtowlower(locale, wc);
184}
185
186static inline
187int strcoll_l(const char *__s1, const char *__s2, locale_t locale)
188{
189  return __xstrcoll(locale, __s1, __s2);
190}
191static inline
192int wcscoll_l(const wchar_t *__s1, const wchar_t *__s2, locale_t locale)
193{
194  return __xwcscoll(locale, __s1, __s2);
195}
196static inline
197size_t strxfrm_l(char *__s1, const char *__s2, size_t __n, locale_t locale)
198{
199  return __xstrxfrm(locale, __s1, __s2, __n);
200}
201
202static inline
203size_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.
212static inline
213size_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
220static inline
221long long strtoll_l(const char *__nptr, char **__endptr,
222    int __base, locale_t locale) {
223  return strtoll(__nptr, __endptr, __base);
224}
225static inline
226long strtol_l(const char *__nptr, char **__endptr,
227    int __base, locale_t locale) {
228  return strtol(__nptr, __endptr, __base);
229}
230static inline
231long double strtold_l(const char *__nptr, char **__endptr,
232    locale_t locale) {
233  return strtold(__nptr, __endptr);
234}
235static inline
236unsigned long long strtoull_l(const char *__nptr, char **__endptr,
237    int __base, locale_t locale) {
238  return strtoull(__nptr, __endptr, __base);
239}
240static inline
241unsigned long strtoul_l(const char *__nptr, char **__endptr,
242    int __base, locale_t locale) {
243  return strtoul(__nptr, __endptr, __base);
244}
245
246static inline
247int 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