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