@@ -94,7 +94,17 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
94
94
95
95
*/
96
96
97
- #if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
97
+ // #include_next has different semantics for module builds.
98
+ // include_next<wchar.h> only works if the current filename is wchar.h,
99
+ // otherwise it just does a regular #include.
100
+ // To solve this, if _LIBCPP_INCLUDE_NEXT_WCHAR is defined, fake an include_next.
101
+ #ifdef _LIBCPP_INCLUDE_NEXT_WCHAR
102
+ # if __has_include_next(<wchar.h>)
103
+ # include_next <wchar.h>
104
+ # elif defined(_LIBCPP_INCLUDE_NEXT_WCHAR)
105
+ # define _LIBCPP_WCHAR_NOT_FOUND
106
+ # endif
107
+ #elif defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
98
108
# include < __cxx03/wchar.h>
99
109
#else
100
110
# include < __config>
@@ -116,92 +126,12 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
116
126
# include_next <wchar.h>
117
127
# endif
118
128
119
- # ifndef _LIBCPP_WCHAR_H
129
+ // Place the header guard here to make it visible to cwchar.
130
+ # if !defined(_LIBCPP_WCHAR_H)
120
131
# define _LIBCPP_WCHAR_H
121
-
122
- # include < __mbstate_t.h> // provide mbstate_t
123
- # include < stddef.h> // provide size_t
124
-
125
- // Determine whether we have const-correct overloads for wcschr and friends.
126
- # if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
127
- # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
128
- # elif defined(__GLIBC_PREREQ)
129
- # if __GLIBC_PREREQ(2, 10)
130
- # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
131
- # endif
132
- # elif defined(_LIBCPP_MSVCRT)
133
- # if defined(_CRT_CONST_CORRECT_OVERLOADS)
134
- # define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
135
- # endif
136
- # endif
137
-
138
- # if _LIBCPP_HAS_WIDE_CHARACTERS
139
- # if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
140
- extern " C++" {
141
- inline _LIBCPP_HIDE_FROM_ABI wchar_t * __libcpp_wcschr (const wchar_t * __s, wchar_t __c) {
142
- return (wchar_t *)wcschr (__s, __c);
143
- }
144
- inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t * wcschr (const wchar_t * __s, wchar_t __c) {
145
- return __libcpp_wcschr (__s, __c);
146
- }
147
- inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t * wcschr (wchar_t * __s, wchar_t __c) {
148
- return __libcpp_wcschr (__s, __c);
149
- }
150
-
151
- inline _LIBCPP_HIDE_FROM_ABI wchar_t * __libcpp_wcspbrk (const wchar_t * __s1, const wchar_t * __s2) {
152
- return (wchar_t *)wcspbrk (__s1, __s2);
153
- }
154
- inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t *
155
- wcspbrk (const wchar_t * __s1, const wchar_t * __s2) {
156
- return __libcpp_wcspbrk (__s1, __s2);
157
- }
158
- inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t * wcspbrk (wchar_t * __s1, const wchar_t * __s2) {
159
- return __libcpp_wcspbrk (__s1, __s2);
160
- }
161
-
162
- inline _LIBCPP_HIDE_FROM_ABI wchar_t * __libcpp_wcsrchr (const wchar_t * __s, wchar_t __c) {
163
- return (wchar_t *)wcsrchr (__s, __c);
164
- }
165
- inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t * wcsrchr (const wchar_t * __s, wchar_t __c) {
166
- return __libcpp_wcsrchr (__s, __c);
167
- }
168
- inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t * wcsrchr (wchar_t * __s, wchar_t __c) {
169
- return __libcpp_wcsrchr (__s, __c);
170
- }
171
-
172
- inline _LIBCPP_HIDE_FROM_ABI wchar_t * __libcpp_wcsstr (const wchar_t * __s1, const wchar_t * __s2) {
173
- return (wchar_t *)wcsstr (__s1, __s2);
174
- }
175
- inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t *
176
- wcsstr (const wchar_t * __s1, const wchar_t * __s2) {
177
- return __libcpp_wcsstr (__s1, __s2);
178
- }
179
- inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t * wcsstr (wchar_t * __s1, const wchar_t * __s2) {
180
- return __libcpp_wcsstr (__s1, __s2);
181
- }
182
-
183
- inline _LIBCPP_HIDE_FROM_ABI wchar_t * __libcpp_wmemchr (const wchar_t * __s, wchar_t __c, size_t __n) {
184
- return (wchar_t *)wmemchr (__s, __c, __n);
185
- }
186
- inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const wchar_t *
187
- wmemchr (const wchar_t * __s, wchar_t __c, size_t __n) {
188
- return __libcpp_wmemchr (__s, __c, __n);
189
- }
190
- inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD wchar_t * wmemchr (wchar_t * __s, wchar_t __c, size_t __n) {
191
- return __libcpp_wmemchr (__s, __c, __n);
192
- }
193
- }
194
- # endif
195
-
196
- # if defined(__cplusplus) && (defined(_LIBCPP_MSVCRT_LIKE) || defined(__MVS__))
197
- extern " C" {
198
- size_t mbsnrtowcs (
199
- wchar_t * __restrict __dst, const char ** __restrict __src, size_t __nmc, size_t __len, mbstate_t * __restrict __ps);
200
- size_t wcsnrtombs (
201
- char * __restrict __dst, const wchar_t ** __restrict __src, size_t __nwc, size_t __len, mbstate_t * __restrict __ps);
202
- } // extern "C"
203
- # endif // __cplusplus && (_LIBCPP_MSVCRT || __MVS__)
204
- # endif // _LIBCPP_HAS_WIDE_CHARACTERS
205
- # endif // _LIBCPP_WCHAR_H
132
+ // This section is not safe to include multiple times, so it goes in a seperate
133
+ // file which is marked as non textual in the modulemap.
134
+ # include < __wchar.h>
135
+ # endif
206
136
207
137
#endif // defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0 commit comments