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