1*58b9f456SAndroid Build Coastguard Worker // -*- C++ -*-
2*58b9f456SAndroid Build Coastguard Worker //===---------------------- __bsd_locale_fallbacks.h ----------------------===//
3*58b9f456SAndroid Build Coastguard Worker //
4*58b9f456SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
5*58b9f456SAndroid Build Coastguard Worker //
6*58b9f456SAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open
7*58b9f456SAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details.
8*58b9f456SAndroid Build Coastguard Worker //
9*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
10*58b9f456SAndroid Build Coastguard Worker // The BSDs have lots of *_l functions. This file provides reimplementations
11*58b9f456SAndroid Build Coastguard Worker // of those functions for non-BSD platforms.
12*58b9f456SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
13*58b9f456SAndroid Build Coastguard Worker
14*58b9f456SAndroid Build Coastguard Worker #ifndef _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
15*58b9f456SAndroid Build Coastguard Worker #define _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
16*58b9f456SAndroid Build Coastguard Worker
17*58b9f456SAndroid Build Coastguard Worker #include <stdlib.h>
18*58b9f456SAndroid Build Coastguard Worker #include <stdarg.h>
19*58b9f456SAndroid Build Coastguard Worker #include <memory>
20*58b9f456SAndroid Build Coastguard Worker
21*58b9f456SAndroid Build Coastguard Worker #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22*58b9f456SAndroid Build Coastguard Worker #pragma GCC system_header
23*58b9f456SAndroid Build Coastguard Worker #endif
24*58b9f456SAndroid Build Coastguard Worker
25*58b9f456SAndroid Build Coastguard Worker _LIBCPP_BEGIN_NAMESPACE_STD
26*58b9f456SAndroid Build Coastguard Worker
27*58b9f456SAndroid Build Coastguard Worker inline _LIBCPP_INLINE_VISIBILITY
decltype(MB_CUR_MAX)28*58b9f456SAndroid Build Coastguard Worker decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l)
29*58b9f456SAndroid Build Coastguard Worker {
30*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
31*58b9f456SAndroid Build Coastguard Worker return MB_CUR_MAX;
32*58b9f456SAndroid Build Coastguard Worker }
33*58b9f456SAndroid Build Coastguard Worker
34*58b9f456SAndroid Build Coastguard Worker inline _LIBCPP_INLINE_VISIBILITY
__libcpp_btowc_l(int __c,locale_t __l)35*58b9f456SAndroid Build Coastguard Worker wint_t __libcpp_btowc_l(int __c, locale_t __l)
36*58b9f456SAndroid Build Coastguard Worker {
37*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
38*58b9f456SAndroid Build Coastguard Worker return btowc(__c);
39*58b9f456SAndroid Build Coastguard Worker }
40*58b9f456SAndroid Build Coastguard Worker
41*58b9f456SAndroid Build Coastguard Worker inline _LIBCPP_INLINE_VISIBILITY
__libcpp_wctob_l(wint_t __c,locale_t __l)42*58b9f456SAndroid Build Coastguard Worker int __libcpp_wctob_l(wint_t __c, locale_t __l)
43*58b9f456SAndroid Build Coastguard Worker {
44*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
45*58b9f456SAndroid Build Coastguard Worker return wctob(__c);
46*58b9f456SAndroid Build Coastguard Worker }
47*58b9f456SAndroid Build Coastguard Worker
48*58b9f456SAndroid Build Coastguard Worker inline _LIBCPP_INLINE_VISIBILITY
__libcpp_wcsnrtombs_l(char * __dest,const wchar_t ** __src,size_t __nwc,size_t __len,mbstate_t * __ps,locale_t __l)49*58b9f456SAndroid Build Coastguard Worker size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc,
50*58b9f456SAndroid Build Coastguard Worker size_t __len, mbstate_t *__ps, locale_t __l)
51*58b9f456SAndroid Build Coastguard Worker {
52*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
53*58b9f456SAndroid Build Coastguard Worker return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
54*58b9f456SAndroid Build Coastguard Worker }
55*58b9f456SAndroid Build Coastguard Worker
56*58b9f456SAndroid Build Coastguard Worker inline _LIBCPP_INLINE_VISIBILITY
__libcpp_wcrtomb_l(char * __s,wchar_t __wc,mbstate_t * __ps,locale_t __l)57*58b9f456SAndroid Build Coastguard Worker size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l)
58*58b9f456SAndroid Build Coastguard Worker {
59*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
60*58b9f456SAndroid Build Coastguard Worker return wcrtomb(__s, __wc, __ps);
61*58b9f456SAndroid Build Coastguard Worker }
62*58b9f456SAndroid Build Coastguard Worker
63*58b9f456SAndroid Build Coastguard Worker inline _LIBCPP_INLINE_VISIBILITY
__libcpp_mbsnrtowcs_l(wchar_t * __dest,const char ** __src,size_t __nms,size_t __len,mbstate_t * __ps,locale_t __l)64*58b9f456SAndroid Build Coastguard Worker size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms,
65*58b9f456SAndroid Build Coastguard Worker size_t __len, mbstate_t *__ps, locale_t __l)
66*58b9f456SAndroid Build Coastguard Worker {
67*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
68*58b9f456SAndroid Build Coastguard Worker return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
69*58b9f456SAndroid Build Coastguard Worker }
70*58b9f456SAndroid Build Coastguard Worker
71*58b9f456SAndroid Build Coastguard Worker inline _LIBCPP_INLINE_VISIBILITY
__libcpp_mbrtowc_l(wchar_t * __pwc,const char * __s,size_t __n,mbstate_t * __ps,locale_t __l)72*58b9f456SAndroid Build Coastguard Worker size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n,
73*58b9f456SAndroid Build Coastguard Worker mbstate_t *__ps, locale_t __l)
74*58b9f456SAndroid Build Coastguard Worker {
75*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
76*58b9f456SAndroid Build Coastguard Worker return mbrtowc(__pwc, __s, __n, __ps);
77*58b9f456SAndroid Build Coastguard Worker }
78*58b9f456SAndroid Build Coastguard Worker
79*58b9f456SAndroid Build Coastguard Worker inline _LIBCPP_INLINE_VISIBILITY
__libcpp_mbtowc_l(wchar_t * __pwc,const char * __pmb,size_t __max,locale_t __l)80*58b9f456SAndroid Build Coastguard Worker int __libcpp_mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l)
81*58b9f456SAndroid Build Coastguard Worker {
82*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
83*58b9f456SAndroid Build Coastguard Worker return mbtowc(__pwc, __pmb, __max);
84*58b9f456SAndroid Build Coastguard Worker }
85*58b9f456SAndroid Build Coastguard Worker
86*58b9f456SAndroid Build Coastguard Worker inline _LIBCPP_INLINE_VISIBILITY
__libcpp_mbrlen_l(const char * __s,size_t __n,mbstate_t * __ps,locale_t __l)87*58b9f456SAndroid Build Coastguard Worker size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l)
88*58b9f456SAndroid Build Coastguard Worker {
89*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
90*58b9f456SAndroid Build Coastguard Worker return mbrlen(__s, __n, __ps);
91*58b9f456SAndroid Build Coastguard Worker }
92*58b9f456SAndroid Build Coastguard Worker
93*58b9f456SAndroid Build Coastguard Worker inline _LIBCPP_INLINE_VISIBILITY
__libcpp_localeconv_l(locale_t __l)94*58b9f456SAndroid Build Coastguard Worker lconv *__libcpp_localeconv_l(locale_t __l)
95*58b9f456SAndroid Build Coastguard Worker {
96*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
97*58b9f456SAndroid Build Coastguard Worker return localeconv();
98*58b9f456SAndroid Build Coastguard Worker }
99*58b9f456SAndroid Build Coastguard Worker
100*58b9f456SAndroid Build Coastguard Worker inline _LIBCPP_INLINE_VISIBILITY
__libcpp_mbsrtowcs_l(wchar_t * __dest,const char ** __src,size_t __len,mbstate_t * __ps,locale_t __l)101*58b9f456SAndroid Build Coastguard Worker size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len,
102*58b9f456SAndroid Build Coastguard Worker mbstate_t *__ps, locale_t __l)
103*58b9f456SAndroid Build Coastguard Worker {
104*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
105*58b9f456SAndroid Build Coastguard Worker return mbsrtowcs(__dest, __src, __len, __ps);
106*58b9f456SAndroid Build Coastguard Worker }
107*58b9f456SAndroid Build Coastguard Worker
108*58b9f456SAndroid Build Coastguard Worker inline
__libcpp_snprintf_l(char * __s,size_t __n,locale_t __l,const char * __format,...)109*58b9f456SAndroid Build Coastguard Worker int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) {
110*58b9f456SAndroid Build Coastguard Worker va_list __va;
111*58b9f456SAndroid Build Coastguard Worker va_start(__va, __format);
112*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
113*58b9f456SAndroid Build Coastguard Worker int __res = vsnprintf(__s, __n, __format, __va);
114*58b9f456SAndroid Build Coastguard Worker va_end(__va);
115*58b9f456SAndroid Build Coastguard Worker return __res;
116*58b9f456SAndroid Build Coastguard Worker }
117*58b9f456SAndroid Build Coastguard Worker
118*58b9f456SAndroid Build Coastguard Worker inline
__libcpp_asprintf_l(char ** __s,locale_t __l,const char * __format,...)119*58b9f456SAndroid Build Coastguard Worker int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) {
120*58b9f456SAndroid Build Coastguard Worker va_list __va;
121*58b9f456SAndroid Build Coastguard Worker va_start(__va, __format);
122*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
123*58b9f456SAndroid Build Coastguard Worker int __res = vasprintf(__s, __format, __va);
124*58b9f456SAndroid Build Coastguard Worker va_end(__va);
125*58b9f456SAndroid Build Coastguard Worker return __res;
126*58b9f456SAndroid Build Coastguard Worker }
127*58b9f456SAndroid Build Coastguard Worker
128*58b9f456SAndroid Build Coastguard Worker inline
__libcpp_sscanf_l(const char * __s,locale_t __l,const char * __format,...)129*58b9f456SAndroid Build Coastguard Worker int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) {
130*58b9f456SAndroid Build Coastguard Worker va_list __va;
131*58b9f456SAndroid Build Coastguard Worker va_start(__va, __format);
132*58b9f456SAndroid Build Coastguard Worker __libcpp_locale_guard __current(__l);
133*58b9f456SAndroid Build Coastguard Worker int __res = vsscanf(__s, __format, __va);
134*58b9f456SAndroid Build Coastguard Worker va_end(__va);
135*58b9f456SAndroid Build Coastguard Worker return __res;
136*58b9f456SAndroid Build Coastguard Worker }
137*58b9f456SAndroid Build Coastguard Worker
138*58b9f456SAndroid Build Coastguard Worker _LIBCPP_END_NAMESPACE_STD
139*58b9f456SAndroid Build Coastguard Worker
140*58b9f456SAndroid Build Coastguard Worker #endif // _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
141