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