New module 'wmemchr'.
[gnulib.git] / lib / wchar.in.h
1 /* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
2
3    Copyright (C) 2007-2011 Free Software Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software Foundation,
17    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18
19 /* Written by Eric Blake.  */
20
21 /*
22  * ISO C 99 <wchar.h> for platforms that have issues.
23  * <http://www.opengroup.org/susv3xbd/wchar.h.html>
24  *
25  * For now, this just ensures proper prerequisite inclusion order and
26  * the declaration of wcwidth().
27  */
28
29 #if __GNUC__ >= 3
30 @PRAGMA_SYSTEM_HEADER@
31 #endif
32 @PRAGMA_COLUMNS@
33
34 #if defined __need_mbstate_t || defined __need_wint_t || (defined __hpux && ((defined _INTTYPES_INCLUDED && !defined strtoimax) || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) || defined _GL_ALREADY_INCLUDING_WCHAR_H
35 /* Special invocation convention:
36    - Inside glibc and uClibc header files.
37    - On HP-UX 11.00 we have a sequence of nested includes
38      <wchar.h> -> <stdlib.h> -> <stdint.h>, and the latter includes <wchar.h>,
39      once indirectly <stdint.h> -> <sys/types.h> -> <inttypes.h> -> <wchar.h>
40      and once directly.  In both situations 'wint_t' is not yet defined,
41      therefore we cannot provide the function overrides; instead include only
42      the system's <wchar.h>.
43    - On IRIX 6.5, similarly, we have an include <wchar.h> -> <wctype.h>, and
44      the latter includes <wchar.h>.  But here, we have no way to detect whether
45      <wctype.h> is completely included or is still being included.  */
46
47 #@INCLUDE_NEXT@ @NEXT_WCHAR_H@
48
49 #else
50 /* Normal invocation convention.  */
51
52 #ifndef _GL_WCHAR_H
53
54 #define _GL_ALREADY_INCLUDING_WCHAR_H
55
56 #if @HAVE_FEATURES_H@
57 # include <features.h> /* for __GLIBC__ */
58 #endif
59
60 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
61    <wchar.h>.
62    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
63    included before <wchar.h>.
64    But avoid namespace pollution on glibc systems.  */
65 #ifndef __GLIBC__
66 # include <stddef.h>
67 # include <stdio.h>
68 # include <time.h>
69 #endif
70
71 /* Include the original <wchar.h> if it exists.
72    Some builds of uClibc lack it.  */
73 /* The include_next requires a split double-inclusion guard.  */
74 #if @HAVE_WCHAR_H@
75 # @INCLUDE_NEXT@ @NEXT_WCHAR_H@
76 #endif
77
78 #undef _GL_ALREADY_INCLUDING_WCHAR_H
79
80 #ifndef _GL_WCHAR_H
81 #define _GL_WCHAR_H
82
83 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
84
85 /* The definition of _GL_ARG_NONNULL is copied here.  */
86
87 /* The definition of _GL_WARN_ON_USE is copied here.  */
88
89
90 /* Define wint_t and WEOF.  (Also done in wctype.in.h.)  */
91 #if !@HAVE_WINT_T@ && !defined wint_t
92 # define wint_t int
93 # ifndef WEOF
94 #  define WEOF -1
95 # endif
96 #else
97 # ifndef WEOF
98 #  define WEOF ((wint_t) -1)
99 # endif
100 #endif
101
102
103 /* Override mbstate_t if it is too small.
104    On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
105    implementing mbrtowc for encodings like UTF-8.  */
106 #if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
107 typedef int rpl_mbstate_t;
108 # undef mbstate_t
109 # define mbstate_t rpl_mbstate_t
110 # define GNULIB_defined_mbstate_t 1
111 #endif
112
113
114 /* Convert a single-byte character to a wide character.  */
115 #if @GNULIB_BTOWC@
116 # if @REPLACE_BTOWC@
117 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
118 #   undef btowc
119 #   define btowc rpl_btowc
120 #  endif
121 _GL_FUNCDECL_RPL (btowc, wint_t, (int c));
122 _GL_CXXALIAS_RPL (btowc, wint_t, (int c));
123 # else
124 #  if !@HAVE_BTOWC@
125 _GL_FUNCDECL_SYS (btowc, wint_t, (int c));
126 #  endif
127 _GL_CXXALIAS_SYS (btowc, wint_t, (int c));
128 # endif
129 _GL_CXXALIASWARN (btowc);
130 #elif defined GNULIB_POSIXCHECK
131 # undef btowc
132 # if HAVE_RAW_DECL_BTOWC
133 _GL_WARN_ON_USE (btowc, "btowc is unportable - "
134                  "use gnulib module btowc for portability");
135 # endif
136 #endif
137
138
139 /* Convert a wide character to a single-byte character.  */
140 #if @GNULIB_WCTOB@
141 # if @REPLACE_WCTOB@
142 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
143 #   undef wctob
144 #   define wctob rpl_wctob
145 #  endif
146 _GL_FUNCDECL_RPL (wctob, int, (wint_t wc));
147 _GL_CXXALIAS_RPL (wctob, int, (wint_t wc));
148 # else
149 #  if !defined wctob && !@HAVE_DECL_WCTOB@
150 /* wctob is provided by gnulib, or wctob exists but is not declared.  */
151 _GL_FUNCDECL_SYS (wctob, int, (wint_t wc));
152 #  endif
153 _GL_CXXALIAS_SYS (wctob, int, (wint_t wc));
154 # endif
155 _GL_CXXALIASWARN (wctob);
156 #elif defined GNULIB_POSIXCHECK
157 # undef wctob
158 # if HAVE_RAW_DECL_WCTOB
159 _GL_WARN_ON_USE (wctob, "wctob is unportable - "
160                  "use gnulib module wctob for portability");
161 # endif
162 #endif
163
164
165 /* Test whether *PS is in the initial state.  */
166 #if @GNULIB_MBSINIT@
167 # if @REPLACE_MBSINIT@
168 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
169 #   undef mbsinit
170 #   define mbsinit rpl_mbsinit
171 #  endif
172 _GL_FUNCDECL_RPL (mbsinit, int, (const mbstate_t *ps));
173 _GL_CXXALIAS_RPL (mbsinit, int, (const mbstate_t *ps));
174 # else
175 #  if !@HAVE_MBSINIT@
176 _GL_FUNCDECL_SYS (mbsinit, int, (const mbstate_t *ps));
177 #  endif
178 _GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps));
179 # endif
180 _GL_CXXALIASWARN (mbsinit);
181 #elif defined GNULIB_POSIXCHECK
182 # undef mbsinit
183 # if HAVE_RAW_DECL_MBSINIT
184 _GL_WARN_ON_USE (mbsinit, "mbsinit is unportable - "
185                  "use gnulib module mbsinit for portability");
186 # endif
187 #endif
188
189
190 /* Convert a multibyte character to a wide character.  */
191 #if @GNULIB_MBRTOWC@
192 # if @REPLACE_MBRTOWC@
193 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
194 #   undef mbrtowc
195 #   define mbrtowc rpl_mbrtowc
196 #  endif
197 _GL_FUNCDECL_RPL (mbrtowc, size_t,
198                   (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
199 _GL_CXXALIAS_RPL (mbrtowc, size_t,
200                   (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
201 # else
202 #  if !@HAVE_MBRTOWC@
203 _GL_FUNCDECL_SYS (mbrtowc, size_t,
204                   (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
205 #  endif
206 _GL_CXXALIAS_SYS (mbrtowc, size_t,
207                   (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
208 # endif
209 _GL_CXXALIASWARN (mbrtowc);
210 #elif defined GNULIB_POSIXCHECK
211 # undef mbrtowc
212 # if HAVE_RAW_DECL_MBRTOWC
213 _GL_WARN_ON_USE (mbrtowc, "mbrtowc is unportable - "
214                  "use gnulib module mbrtowc for portability");
215 # endif
216 #endif
217
218
219 /* Recognize a multibyte character.  */
220 #if @GNULIB_MBRLEN@
221 # if @REPLACE_MBRLEN@
222 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
223 #   undef mbrlen
224 #   define mbrlen rpl_mbrlen
225 #  endif
226 _GL_FUNCDECL_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
227 _GL_CXXALIAS_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
228 # else
229 #  if !@HAVE_MBRLEN@
230 _GL_FUNCDECL_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
231 #  endif
232 _GL_CXXALIAS_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
233 # endif
234 _GL_CXXALIASWARN (mbrlen);
235 #elif defined GNULIB_POSIXCHECK
236 # undef mbrlen
237 # if HAVE_RAW_DECL_MBRLEN
238 _GL_WARN_ON_USE (mbrlen, "mbrlen is unportable - "
239                  "use gnulib module mbrlen for portability");
240 # endif
241 #endif
242
243
244 /* Convert a string to a wide string.  */
245 #if @GNULIB_MBSRTOWCS@
246 # if @REPLACE_MBSRTOWCS@
247 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
248 #   undef mbsrtowcs
249 #   define mbsrtowcs rpl_mbsrtowcs
250 #  endif
251 _GL_FUNCDECL_RPL (mbsrtowcs, size_t,
252                   (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
253                   _GL_ARG_NONNULL ((2)));
254 _GL_CXXALIAS_RPL (mbsrtowcs, size_t,
255                   (wchar_t *dest, const char **srcp, size_t len,
256                    mbstate_t *ps));
257 # else
258 #  if !@HAVE_MBSRTOWCS@
259 _GL_FUNCDECL_SYS (mbsrtowcs, size_t,
260                   (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
261                   _GL_ARG_NONNULL ((2)));
262 #  endif
263 _GL_CXXALIAS_SYS (mbsrtowcs, size_t,
264                   (wchar_t *dest, const char **srcp, size_t len,
265                    mbstate_t *ps));
266 # endif
267 _GL_CXXALIASWARN (mbsrtowcs);
268 #elif defined GNULIB_POSIXCHECK
269 # undef mbsrtowcs
270 # if HAVE_RAW_DECL_MBSRTOWCS
271 _GL_WARN_ON_USE (mbsrtowcs, "mbsrtowcs is unportable - "
272                  "use gnulib module mbsrtowcs for portability");
273 # endif
274 #endif
275
276
277 /* Convert a string to a wide string.  */
278 #if @GNULIB_MBSNRTOWCS@
279 # if @REPLACE_MBSNRTOWCS@
280 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
281 #   undef mbsnrtowcs
282 #   define mbsnrtowcs rpl_mbsnrtowcs
283 #  endif
284 _GL_FUNCDECL_RPL (mbsnrtowcs, size_t,
285                   (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
286                    mbstate_t *ps)
287                   _GL_ARG_NONNULL ((2)));
288 _GL_CXXALIAS_RPL (mbsnrtowcs, size_t,
289                   (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
290                    mbstate_t *ps));
291 # else
292 #  if !@HAVE_MBSNRTOWCS@
293 _GL_FUNCDECL_SYS (mbsnrtowcs, size_t,
294                   (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
295                    mbstate_t *ps)
296                   _GL_ARG_NONNULL ((2)));
297 #  endif
298 _GL_CXXALIAS_SYS (mbsnrtowcs, size_t,
299                   (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
300                    mbstate_t *ps));
301 # endif
302 _GL_CXXALIASWARN (mbsnrtowcs);
303 #elif defined GNULIB_POSIXCHECK
304 # undef mbsnrtowcs
305 # if HAVE_RAW_DECL_MBSNRTOWCS
306 _GL_WARN_ON_USE (mbsnrtowcs, "mbsnrtowcs is unportable - "
307                  "use gnulib module mbsnrtowcs for portability");
308 # endif
309 #endif
310
311
312 /* Convert a wide character to a multibyte character.  */
313 #if @GNULIB_WCRTOMB@
314 # if @REPLACE_WCRTOMB@
315 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
316 #   undef wcrtomb
317 #   define wcrtomb rpl_wcrtomb
318 #  endif
319 _GL_FUNCDECL_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
320 _GL_CXXALIAS_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
321 # else
322 #  if !@HAVE_WCRTOMB@
323 _GL_FUNCDECL_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
324 #  endif
325 _GL_CXXALIAS_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
326 # endif
327 _GL_CXXALIASWARN (wcrtomb);
328 #elif defined GNULIB_POSIXCHECK
329 # undef wcrtomb
330 # if HAVE_RAW_DECL_WCRTOMB
331 _GL_WARN_ON_USE (wcrtomb, "wcrtomb is unportable - "
332                  "use gnulib module wcrtomb for portability");
333 # endif
334 #endif
335
336
337 /* Convert a wide string to a string.  */
338 #if @GNULIB_WCSRTOMBS@
339 # if @REPLACE_WCSRTOMBS@
340 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
341 #   undef wcsrtombs
342 #   define wcsrtombs rpl_wcsrtombs
343 #  endif
344 _GL_FUNCDECL_RPL (wcsrtombs, size_t,
345                   (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
346                   _GL_ARG_NONNULL ((2)));
347 _GL_CXXALIAS_RPL (wcsrtombs, size_t,
348                   (char *dest, const wchar_t **srcp, size_t len,
349                    mbstate_t *ps));
350 # else
351 #  if !@HAVE_WCSRTOMBS@
352 _GL_FUNCDECL_SYS (wcsrtombs, size_t,
353                   (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
354                   _GL_ARG_NONNULL ((2)));
355 #  endif
356 _GL_CXXALIAS_SYS (wcsrtombs, size_t,
357                   (char *dest, const wchar_t **srcp, size_t len,
358                    mbstate_t *ps));
359 # endif
360 _GL_CXXALIASWARN (wcsrtombs);
361 #elif defined GNULIB_POSIXCHECK
362 # undef wcsrtombs
363 # if HAVE_RAW_DECL_WCSRTOMBS
364 _GL_WARN_ON_USE (wcsrtombs, "wcsrtombs is unportable - "
365                  "use gnulib module wcsrtombs for portability");
366 # endif
367 #endif
368
369
370 /* Convert a wide string to a string.  */
371 #if @GNULIB_WCSNRTOMBS@
372 # if @REPLACE_WCSNRTOMBS@
373 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
374 #   undef wcsnrtombs
375 #   define wcsnrtombs rpl_wcsnrtombs
376 #  endif
377 _GL_FUNCDECL_RPL (wcsnrtombs, size_t,
378                   (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
379                    mbstate_t *ps)
380                   _GL_ARG_NONNULL ((2)));
381 _GL_CXXALIAS_RPL (wcsnrtombs, size_t,
382                   (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
383                    mbstate_t *ps));
384 # else
385 #  if !@HAVE_WCSNRTOMBS@
386 _GL_FUNCDECL_SYS (wcsnrtombs, size_t,
387                   (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
388                    mbstate_t *ps)
389                   _GL_ARG_NONNULL ((2)));
390 #  endif
391 _GL_CXXALIAS_SYS (wcsnrtombs, size_t,
392                   (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
393                    mbstate_t *ps));
394 # endif
395 _GL_CXXALIASWARN (wcsnrtombs);
396 #elif defined GNULIB_POSIXCHECK
397 # undef wcsnrtombs
398 # if HAVE_RAW_DECL_WCSNRTOMBS
399 _GL_WARN_ON_USE (wcsnrtombs, "wcsnrtombs is unportable - "
400                  "use gnulib module wcsnrtombs for portability");
401 # endif
402 #endif
403
404
405 /* Return the number of screen columns needed for WC.  */
406 #if @GNULIB_WCWIDTH@
407 # if @REPLACE_WCWIDTH@
408 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
409 #   undef wcwidth
410 #   define wcwidth rpl_wcwidth
411 #  endif
412 _GL_FUNCDECL_RPL (wcwidth, int, (wchar_t));
413 _GL_CXXALIAS_RPL (wcwidth, int, (wchar_t));
414 # else
415 #  if !@HAVE_DECL_WCWIDTH@
416 /* wcwidth exists but is not declared.  */
417 _GL_FUNCDECL_SYS (wcwidth, int, (wchar_t));
418 #  endif
419 _GL_CXXALIAS_SYS (wcwidth, int, (wchar_t));
420 # endif
421 _GL_CXXALIASWARN (wcwidth);
422 #elif defined GNULIB_POSIXCHECK
423 # undef wcwidth
424 # if HAVE_RAW_DECL_WCWIDTH
425 _GL_WARN_ON_USE (wcwidth, "wcwidth is unportable - "
426                  "use gnulib module wcwidth for portability");
427 # endif
428 #endif
429
430
431 /* Search N wide characters of S for C.  */
432 #if @GNULIB_WMEMCHR@
433 # if !@HAVE_WMEMCHR@
434 _GL_FUNCDECL_SYS (wmemchr, wchar_t *, (const wchar_t *s, wchar_t c, size_t n));
435 # endif
436 _GL_CXXALIAS_SYS (wmemchr, wchar_t *, (const wchar_t *s, wchar_t c, size_t n));
437 _GL_CXXALIASWARN (wmemchr);
438 #elif defined GNULIB_POSIXCHECK
439 # undef wmemchr
440 # if HAVE_RAW_DECL_WMEMCHR
441 _GL_WARN_ON_USE (wmemchr, "wmemchr is unportable - "
442                  "use gnulib module wmemchr for portability");
443 # endif
444 #endif
445
446
447 #endif /* _GL_WCHAR_H */
448 #endif /* _GL_WCHAR_H */
449 #endif