wchar.h 8.6 KB

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