Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 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 <memory> |
| 19 | |
| 20 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 21 | |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 22 | inline _LIBCPP_ALWAYS_INLINE |
| 23 | decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l) |
| 24 | { |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 25 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 26 | return MB_CUR_MAX; |
| 27 | } |
| 28 | |
| 29 | inline _LIBCPP_ALWAYS_INLINE |
| 30 | wint_t __libcpp_btowc_l(int __c, locale_t __l) |
| 31 | { |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 32 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 33 | return btowc(__c); |
| 34 | } |
| 35 | |
| 36 | inline _LIBCPP_ALWAYS_INLINE |
| 37 | int __libcpp_wctob_l(wint_t __c, locale_t __l) |
| 38 | { |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 39 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 40 | return wctob(__c); |
| 41 | } |
| 42 | |
| 43 | inline _LIBCPP_ALWAYS_INLINE |
| 44 | size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc, |
| 45 | size_t __len, mbstate_t *__ps, locale_t __l) |
| 46 | { |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 47 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 48 | return wcsnrtombs(__dest, __src, __nwc, __len, __ps); |
| 49 | } |
| 50 | |
| 51 | inline _LIBCPP_ALWAYS_INLINE |
| 52 | size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l) |
| 53 | { |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 54 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 55 | return wcrtomb(__s, __wc, __ps); |
| 56 | } |
| 57 | |
| 58 | inline _LIBCPP_ALWAYS_INLINE |
| 59 | size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms, |
| 60 | size_t __len, mbstate_t *__ps, locale_t __l) |
| 61 | { |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 62 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 63 | return mbsnrtowcs(__dest, __src, __nms, __len, __ps); |
| 64 | } |
| 65 | |
| 66 | inline _LIBCPP_ALWAYS_INLINE |
| 67 | size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n, |
| 68 | mbstate_t *__ps, locale_t __l) |
| 69 | { |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 70 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 71 | return mbrtowc(__pwc, __s, __n, __ps); |
| 72 | } |
| 73 | |
| 74 | inline _LIBCPP_ALWAYS_INLINE |
| 75 | int __libcpp_mbtowc_l(wchar_t *__pwc, const char *__pmb, size_t __max, locale_t __l) |
| 76 | { |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 77 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 78 | return mbtowc(__pwc, __pmb, __max); |
| 79 | } |
| 80 | |
| 81 | inline _LIBCPP_ALWAYS_INLINE |
| 82 | size_t __libcpp_mbrlen_l(const char *__s, size_t __n, mbstate_t *__ps, locale_t __l) |
| 83 | { |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 84 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 85 | return mbrlen(__s, __n, __ps); |
| 86 | } |
| 87 | |
| 88 | inline _LIBCPP_ALWAYS_INLINE |
| 89 | lconv *__libcpp_localeconv_l(locale_t __l) |
| 90 | { |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 91 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 92 | return localeconv(); |
| 93 | } |
| 94 | |
| 95 | inline _LIBCPP_ALWAYS_INLINE |
| 96 | size_t __libcpp_mbsrtowcs_l(wchar_t *__dest, const char **__src, size_t __len, |
| 97 | mbstate_t *__ps, locale_t __l) |
| 98 | { |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 99 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 100 | return mbsrtowcs(__dest, __src, __len, __ps); |
| 101 | } |
| 102 | |
| 103 | inline |
| 104 | int __libcpp_snprintf_l(char *__s, size_t __n, locale_t __l, const char *__format, ...) { |
| 105 | va_list __va; |
| 106 | va_start(__va, __format); |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 107 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 108 | int __res = vsnprintf(__s, __n, __format, __va); |
| 109 | va_end(__va); |
| 110 | return __res; |
| 111 | } |
| 112 | |
| 113 | inline |
| 114 | int __libcpp_asprintf_l(char **__s, locale_t __l, const char *__format, ...) { |
| 115 | va_list __va; |
| 116 | va_start(__va, __format); |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 117 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 118 | int __res = vasprintf(__s, __format, __va); |
| 119 | va_end(__va); |
| 120 | return __res; |
| 121 | } |
| 122 | |
| 123 | inline |
| 124 | int __libcpp_sscanf_l(const char *__s, locale_t __l, const char *__format, ...) { |
| 125 | va_list __va; |
| 126 | va_start(__va, __format); |
Eric Fiselier | b4ddab2 | 2017-05-08 22:02:43 +0000 | [diff] [blame^] | 127 | __libcpp_locale_guard __current(__l); |
Ben Craig | d2f15ba | 2016-03-09 15:39:39 +0000 | [diff] [blame] | 128 | int __res = vsscanf(__s, __format, __va); |
| 129 | va_end(__va); |
| 130 | return __res; |
| 131 | } |
| 132 | |
| 133 | _LIBCPP_END_NAMESPACE_STD |
| 134 | |
| 135 | #endif // _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H |