1 /* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
3 Copyright (C) 2007-2010 Free Software Foundation, Inc.
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)
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.
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. */
19 /* Written by Eric Blake. */
22 * ISO C 99 <wchar.h> for platforms that have issues.
23 * <http://www.opengroup.org/susv3xbd/wchar.h.html>
25 * For now, this just ensures proper prerequisite inclusion order and
26 * the declaration of wcwidth().
30 @PRAGMA_SYSTEM_HEADER@
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. */
47 #@INCLUDE_NEXT@ @NEXT_WCHAR_H@
50 /* Normal invocation convention. */
54 #define _GL_ALREADY_INCLUDING_WCHAR_H
57 # include <features.h> /* for __GLIBC__ */
60 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
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. */
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. */
75 # @INCLUDE_NEXT@ @NEXT_WCHAR_H@
78 #undef _GL_ALREADY_INCLUDING_WCHAR_H
83 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
85 /* The definition of _GL_ARG_NONNULL is copied here. */
87 /* The definition of _GL_WARN_ON_USE is copied here. */
90 /* Define wint_t and WEOF. (Also done in wctype.in.h.) */
91 #if !@HAVE_WINT_T@ && !defined wint_t
98 # define WEOF ((wint_t) -1)
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;
109 # define mbstate_t rpl_mbstate_t
110 # define GNULIB_defined_mbstate_t 1
114 /* Convert a single-byte character to a wide character. */
117 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
119 # define btowc rpl_btowc
121 _GL_FUNCDECL_RPL (btowc, wint_t, (int c));
122 _GL_CXXALIAS_RPL (btowc, wint_t, (int c));
125 _GL_FUNCDECL_SYS (btowc, wint_t, (int c));
127 _GL_CXXALIAS_SYS (btowc, wint_t, (int c));
129 _GL_CXXALIASWARN (btowc);
130 #elif defined GNULIB_POSIXCHECK
132 # if HAVE_RAW_DECL_BTOWC
133 _GL_WARN_ON_USE (btowc, "btowc is unportable - "
134 "use gnulib module btowc for portability");
139 /* Convert a wide character to a single-byte character. */
142 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
144 # define wctob rpl_wctob
146 _GL_FUNCDECL_RPL (wctob, int, (wint_t wc));
147 _GL_CXXALIAS_RPL (wctob, int, (wint_t wc));
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));
153 _GL_CXXALIAS_SYS (wctob, int, (wint_t wc));
155 _GL_CXXALIASWARN (wctob);
156 #elif defined GNULIB_POSIXCHECK
158 # if HAVE_RAW_DECL_WCTOB
159 _GL_WARN_ON_USE (wctob, "wctob is unportable - "
160 "use gnulib module wctob for portability");
165 /* Test whether *PS is in the initial state. */
167 # if @REPLACE_MBSINIT@
168 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
170 # define mbsinit rpl_mbsinit
172 _GL_FUNCDECL_RPL (mbsinit, int, (const mbstate_t *ps));
173 _GL_CXXALIAS_RPL (mbsinit, int, (const mbstate_t *ps));
176 _GL_FUNCDECL_SYS (mbsinit, int, (const mbstate_t *ps));
178 _GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps));
180 _GL_CXXALIASWARN (mbsinit);
181 #elif defined GNULIB_POSIXCHECK
183 # if HAVE_RAW_DECL_MBSINIT
184 _GL_WARN_ON_USE (mbsinit, "mbsinit is unportable - "
185 "use gnulib module mbsinit for portability");
190 /* Convert a multibyte character to a wide character. */
192 # if @REPLACE_MBRTOWC@
193 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
195 # define mbrtowc rpl_mbrtowc
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));
203 _GL_FUNCDECL_SYS (mbrtowc, size_t,
204 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
206 _GL_CXXALIAS_SYS (mbrtowc, size_t,
207 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
209 _GL_CXXALIASWARN (mbrtowc);
210 #elif defined GNULIB_POSIXCHECK
212 # if HAVE_RAW_DECL_MBRTOWC
213 _GL_WARN_ON_USE (mbrtowc, "mbrtowc is unportable - "
214 "use gnulib module mbrtowc for portability");
219 /* Recognize a multibyte character. */
221 # if @REPLACE_MBRLEN@
222 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
224 # define mbrlen rpl_mbrlen
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));
230 _GL_FUNCDECL_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
232 _GL_CXXALIAS_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
234 _GL_CXXALIASWARN (mbrlen);
235 #elif defined GNULIB_POSIXCHECK
237 # if HAVE_RAW_DECL_MBRLEN
238 _GL_WARN_ON_USE (mbrlen, "mbrlen is unportable - "
239 "use gnulib module mbrlen for portability");
244 /* Convert a string to a wide string. */
245 #if @GNULIB_MBSRTOWCS@
246 # if @REPLACE_MBSRTOWCS@
247 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
249 # define mbsrtowcs rpl_mbsrtowcs
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,
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)));
263 _GL_CXXALIAS_SYS (mbsrtowcs, size_t,
264 (wchar_t *dest, const char **srcp, size_t len,
267 _GL_CXXALIASWARN (mbsrtowcs);
268 #elif defined GNULIB_POSIXCHECK
270 # if HAVE_RAW_DECL_MBSRTOWCS
271 _GL_WARN_ON_USE (mbsrtowcs, "mbsrtowcs is unportable - "
272 "use gnulib module mbsrtowcs for portability");
277 /* Convert a string to a wide string. */
278 #if @GNULIB_MBSNRTOWCS@
279 # if @REPLACE_MBSNRTOWCS@
280 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
282 # define mbsnrtowcs rpl_mbsnrtowcs
284 _GL_FUNCDECL_RPL (mbsnrtowcs, size_t,
285 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
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,
292 # if !@HAVE_MBSNRTOWCS@
293 _GL_FUNCDECL_SYS (mbsnrtowcs, size_t,
294 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
296 _GL_ARG_NONNULL ((2)));
298 _GL_CXXALIAS_SYS (mbsnrtowcs, size_t,
299 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
302 _GL_CXXALIASWARN (mbsnrtowcs);
303 #elif defined GNULIB_POSIXCHECK
305 # if HAVE_RAW_DECL_MBSNRTOWCS
306 _GL_WARN_ON_USE (mbsnrtowcs, "mbsnrtowcs is unportable - "
307 "use gnulib module mbsnrtowcs for portability");
312 /* Convert a wide character to a multibyte character. */
314 # if @REPLACE_WCRTOMB@
315 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
317 # define wcrtomb rpl_wcrtomb
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));
323 _GL_FUNCDECL_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
325 _GL_CXXALIAS_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
327 _GL_CXXALIASWARN (wcrtomb);
328 #elif defined GNULIB_POSIXCHECK
330 # if HAVE_RAW_DECL_WCRTOMB
331 _GL_WARN_ON_USE (wcrtomb, "wcrtomb is unportable - "
332 "use gnulib module wcrtomb for portability");
337 /* Convert a wide string to a string. */
338 #if @GNULIB_WCSRTOMBS@
339 # if @REPLACE_WCSRTOMBS@
340 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
342 # define wcsrtombs rpl_wcsrtombs
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,
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)));
356 _GL_CXXALIAS_SYS (wcsrtombs, size_t,
357 (char *dest, const wchar_t **srcp, size_t len,
360 _GL_CXXALIASWARN (wcsrtombs);
361 #elif defined GNULIB_POSIXCHECK
363 # if HAVE_RAW_DECL_WCSRTOMBS
364 _GL_WARN_ON_USE (wcsrtombs, "wcsrtombs is unportable - "
365 "use gnulib module wcsrtombs for portability");
370 /* Convert a wide string to a string. */
371 #if @GNULIB_WCSNRTOMBS@
372 # if @REPLACE_WCSNRTOMBS@
373 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
375 # define wcsnrtombs rpl_wcsnrtombs
377 _GL_FUNCDECL_RPL (wcsnrtombs, size_t,
378 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
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,
385 # if !@HAVE_WCSNRTOMBS@
386 _GL_FUNCDECL_SYS (wcsnrtombs, size_t,
387 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
389 _GL_ARG_NONNULL ((2)));
391 _GL_CXXALIAS_SYS (wcsnrtombs, size_t,
392 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
395 _GL_CXXALIASWARN (wcsnrtombs);
396 #elif defined GNULIB_POSIXCHECK
398 # if HAVE_RAW_DECL_WCSNRTOMBS
399 _GL_WARN_ON_USE (wcsnrtombs, "wcsnrtombs is unportable - "
400 "use gnulib module wcsnrtombs for portability");
405 /* Return the number of screen columns needed for WC. */
407 # if @REPLACE_WCWIDTH@
408 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
410 # define wcwidth rpl_wcwidth
412 _GL_FUNCDECL_RPL (wcwidth, int, (wchar_t));
413 _GL_CXXALIAS_RPL (wcwidth, int, (wchar_t));
415 # if !@HAVE_DECL_WCWIDTH@
416 /* wcwidth exists but is not declared. */
417 _GL_FUNCDECL_SYS (wcwidth, int, (wchar_t));
419 _GL_CXXALIAS_SYS (wcwidth, int, (wchar_t));
421 _GL_CXXALIASWARN (wcwidth);
422 #elif defined GNULIB_POSIXCHECK
424 # if HAVE_RAW_DECL_WCWIDTH
425 _GL_WARN_ON_USE (wcwidth, "wcwidth is unportable - "
426 "use gnulib module wcwidth for portability");
431 #endif /* _GL_WCHAR_H */
432 #endif /* _GL_WCHAR_H */