__bsd_locale_fallbacks.h 3.9 KB

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