wchar.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. #if defined(__need_wint_t) || defined(__need_mbstate_t)
  10. # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  11. # pragma GCC system_header
  12. # endif
  13. # include_next <wchar.h>
  14. #elif !defined(_LIBCPP_WCHAR_H)
  15. # define _LIBCPP_WCHAR_H
  16. /*
  17. wchar.h synopsis
  18. Macros:
  19. NULL
  20. WCHAR_MAX
  21. WCHAR_MIN
  22. WEOF
  23. Types:
  24. mbstate_t
  25. size_t
  26. tm
  27. wint_t
  28. int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...);
  29. int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...);
  30. int swprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, ...);
  31. int swscanf(const wchar_t* restrict s, const wchar_t* restrict format, ...);
  32. int vfwprintf(FILE* restrict stream, const wchar_t* restrict format, va_list arg);
  33. int vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list arg); // C99
  34. int vswprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, va_list arg);
  35. int vswscanf(const wchar_t* restrict s, const wchar_t* restrict format, va_list arg); // C99
  36. int vwprintf(const wchar_t* restrict format, va_list arg);
  37. int vwscanf(const wchar_t* restrict format, va_list arg); // C99
  38. int wprintf(const wchar_t* restrict format, ...);
  39. int wscanf(const wchar_t* restrict format, ...);
  40. wint_t fgetwc(FILE* stream);
  41. wchar_t* fgetws(wchar_t* restrict s, int n, FILE* restrict stream);
  42. wint_t fputwc(wchar_t c, FILE* stream);
  43. int fputws(const wchar_t* restrict s, FILE* restrict stream);
  44. int fwide(FILE* stream, int mode);
  45. wint_t getwc(FILE* stream);
  46. wint_t getwchar();
  47. wint_t putwc(wchar_t c, FILE* stream);
  48. wint_t putwchar(wchar_t c);
  49. wint_t ungetwc(wint_t c, FILE* stream);
  50. double wcstod(const wchar_t* restrict nptr, wchar_t** restrict endptr);
  51. float wcstof(const wchar_t* restrict nptr, wchar_t** restrict endptr); // C99
  52. long double wcstold(const wchar_t* restrict nptr, wchar_t** restrict endptr); // C99
  53. long wcstol(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
  54. long long wcstoll(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); // C99
  55. unsigned long wcstoul(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
  56. unsigned long long wcstoull(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); // C99
  57. wchar_t* wcscpy(wchar_t* restrict s1, const wchar_t* restrict s2);
  58. wchar_t* wcsncpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
  59. wchar_t* wcscat(wchar_t* restrict s1, const wchar_t* restrict s2);
  60. wchar_t* wcsncat(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
  61. int wcscmp(const wchar_t* s1, const wchar_t* s2);
  62. int wcscoll(const wchar_t* s1, const wchar_t* s2);
  63. int wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n);
  64. size_t wcsxfrm(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
  65. const wchar_t* wcschr(const wchar_t* s, wchar_t c);
  66. wchar_t* wcschr( wchar_t* s, wchar_t c);
  67. size_t wcscspn(const wchar_t* s1, const wchar_t* s2);
  68. size_t wcslen(const wchar_t* s);
  69. const wchar_t* wcspbrk(const wchar_t* s1, const wchar_t* s2);
  70. wchar_t* wcspbrk( wchar_t* s1, const wchar_t* s2);
  71. const wchar_t* wcsrchr(const wchar_t* s, wchar_t c);
  72. wchar_t* wcsrchr( wchar_t* s, wchar_t c);
  73. size_t wcsspn(const wchar_t* s1, const wchar_t* s2);
  74. const wchar_t* wcsstr(const wchar_t* s1, const wchar_t* s2);
  75. wchar_t* wcsstr( wchar_t* s1, const wchar_t* s2);
  76. wchar_t* wcstok(wchar_t* restrict s1, const wchar_t* restrict s2, wchar_t** restrict ptr);
  77. const wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n);
  78. wchar_t* wmemchr( wchar_t* s, wchar_t c, size_t n);
  79. int wmemcmp(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
  80. wchar_t* wmemcpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
  81. wchar_t* wmemmove(wchar_t* s1, const wchar_t* s2, size_t n);
  82. wchar_t* wmemset(wchar_t* s, wchar_t c, size_t n);
  83. size_t wcsftime(wchar_t* restrict s, size_t maxsize, const wchar_t* restrict format,
  84. const tm* restrict timeptr);
  85. wint_t btowc(int c);
  86. int wctob(wint_t c);
  87. int mbsinit(const mbstate_t* ps);
  88. size_t mbrlen(const char* restrict s, size_t n, mbstate_t* restrict ps);
  89. size_t mbrtowc(wchar_t* restrict pwc, const char* restrict s, size_t n, mbstate_t* restrict ps);
  90. size_t wcrtomb(char* restrict s, wchar_t wc, mbstate_t* restrict ps);
  91. size_t mbsrtowcs(wchar_t* restrict dst, const char** restrict src, size_t len,
  92. mbstate_t* restrict ps);
  93. size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
  94. mbstate_t* restrict ps);
  95. */
  96. # include <__config>
  97. # include <stddef.h>
  98. # if defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS)
  99. # error \
  100. "The <wchar.h> header is not supported since libc++ has been configured with LIBCXX_ENABLE_WIDE_CHARACTERS disabled"
  101. # endif
  102. # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  103. # pragma GCC system_header
  104. # endif
  105. // We define this here to support older versions of glibc <wchar.h> that do
  106. // not define this for clang.
  107. # ifdef __cplusplus
  108. # define __CORRECT_ISO_CPP_WCHAR_H_PROTO
  109. # endif
  110. # if __has_include_next(<wchar.h>)
  111. # include_next <wchar.h>
  112. # else
  113. # include <__mbstate_t.h> // make sure we have mbstate_t regardless of the existence of <wchar.h>
  114. # endif
  115. // Determine whether we have const-correct overloads for wcschr and friends.
  116. # if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
  117. # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
  118. # elif defined(__GLIBC_PREREQ)
  119. # if __GLIBC_PREREQ(2, 10)
  120. # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
  121. # endif
  122. # elif defined(_LIBCPP_MSVCRT)
  123. # if defined(_CRT_CONST_CORRECT_OVERLOADS)
  124. # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
  125. # endif
  126. # endif
  127. # if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
  128. extern "C++" {
  129. inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {
  130. return (wchar_t*)wcschr(__s, __c);
  131. }
  132. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {
  133. return __libcpp_wcschr(__s, __c);
  134. }
  135. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcschr(wchar_t* __s, wchar_t __c) {
  136. return __libcpp_wcschr(__s, __c);
  137. }
  138. inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {
  139. return (wchar_t*)wcspbrk(__s1, __s2);
  140. }
  141. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
  142. wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {
  143. return __libcpp_wcspbrk(__s1, __s2);
  144. }
  145. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcspbrk(wchar_t* __s1, const wchar_t* __s2) {
  146. return __libcpp_wcspbrk(__s1, __s2);
  147. }
  148. inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcsrchr(const wchar_t* __s, wchar_t __c) {
  149. return (wchar_t*)wcsrchr(__s, __c);
  150. }
  151. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {
  152. return __libcpp_wcsrchr(__s, __c);
  153. }
  154. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcsrchr(wchar_t* __s, wchar_t __c) {
  155. return __libcpp_wcsrchr(__s, __c);
  156. }
  157. inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {
  158. return (wchar_t*)wcsstr(__s1, __s2);
  159. }
  160. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
  161. wcsstr(const wchar_t* __s1, const wchar_t* __s2) {
  162. return __libcpp_wcsstr(__s1, __s2);
  163. }
  164. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wcsstr(wchar_t* __s1, const wchar_t* __s2) {
  165. return __libcpp_wcsstr(__s1, __s2);
  166. }
  167. inline _LIBCPP_HIDE_FROM_ABI wchar_t* __libcpp_wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {
  168. return (wchar_t*)wmemchr(__s, __c, __n);
  169. }
  170. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
  171. wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {
  172. return __libcpp_wmemchr(__s, __c, __n);
  173. }
  174. inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t* wmemchr(wchar_t* __s, wchar_t __c, size_t __n) {
  175. return __libcpp_wmemchr(__s, __c, __n);
  176. }
  177. }
  178. # endif
  179. # if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__))
  180. extern "C" {
  181. size_t mbsnrtowcs(
  182. wchar_t* __restrict __dst, const char** __restrict __src, size_t __nmc, size_t __len, mbstate_t* __restrict __ps);
  183. size_t wcsnrtombs(
  184. char* __restrict __dst, const wchar_t** __restrict __src, size_t __nwc, size_t __len, mbstate_t* __restrict __ps);
  185. } // extern "C"
  186. # endif // __cplusplus && (_LIBCPP_MSVCRT || __MVS__)
  187. #endif // _LIBCPP_WCHAR_H