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
56 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
58 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
59 included before <wchar.h>.
60 But avoid namespace pollution on glibc systems. */
67 /* Include the original <wchar.h> if it exists.
68 Some builds of uClibc lack it. */
69 /* The include_next requires a split double-inclusion guard. */
71 # @INCLUDE_NEXT@ @NEXT_WCHAR_H@
74 #undef _GL_ALREADY_INCLUDING_WCHAR_H
79 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
81 /* The definition of _GL_ARG_NONNULL is copied here. */
83 /* The definition of _GL_WARN_ON_USE is copied here. */
86 /* Define wint_t and WEOF. (Also done in wctype.in.h.) */
87 #if !@HAVE_WINT_T@ && !defined wint_t
94 # define WEOF ((wint_t) -1)
99 /* Override mbstate_t if it is too small.
100 On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
101 implementing mbrtowc for encodings like UTF-8. */
102 #if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
103 typedef int rpl_mbstate_t;
105 # define mbstate_t rpl_mbstate_t
106 # define GNULIB_defined_mbstate_t 1
110 /* Convert a single-byte character to a wide character. */
113 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
115 # define btowc rpl_btowc
117 _GL_FUNCDECL_RPL (btowc, wint_t, (int c));
118 _GL_CXXALIAS_RPL (btowc, wint_t, (int c));
121 _GL_FUNCDECL_SYS (btowc, wint_t, (int c));
123 _GL_CXXALIAS_SYS (btowc, wint_t, (int c));
125 _GL_CXXALIASWARN (btowc);
126 #elif defined GNULIB_POSIXCHECK
128 # if HAVE_RAW_DECL_BTOWC
129 _GL_WARN_ON_USE (btowc, "btowc is unportable - "
130 "use gnulib module btowc for portability");
135 /* Convert a wide character to a single-byte character. */
138 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
140 # define wctob rpl_wctob
142 _GL_FUNCDECL_RPL (wctob, int, (wint_t wc));
143 _GL_CXXALIAS_RPL (wctob, int, (wint_t wc));
145 # if !defined wctob && !@HAVE_DECL_WCTOB@
146 /* wctob is provided by gnulib, or wctob exists but is not declared. */
147 _GL_FUNCDECL_SYS (wctob, int, (wint_t wc));
149 _GL_CXXALIAS_SYS (wctob, int, (wint_t wc));
151 _GL_CXXALIASWARN (wctob);
152 #elif defined GNULIB_POSIXCHECK
154 # if HAVE_RAW_DECL_WCTOB
155 _GL_WARN_ON_USE (wctob, "wctob is unportable - "
156 "use gnulib module wctob for portability");
161 /* Test whether *PS is in the initial state. */
163 # if @REPLACE_MBSINIT@
164 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
166 # define mbsinit rpl_mbsinit
168 _GL_FUNCDECL_RPL (mbsinit, int, (const mbstate_t *ps));
169 _GL_CXXALIAS_RPL (mbsinit, int, (const mbstate_t *ps));
172 _GL_FUNCDECL_SYS (mbsinit, int, (const mbstate_t *ps));
174 _GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps));
176 _GL_CXXALIASWARN (mbsinit);
177 #elif defined GNULIB_POSIXCHECK
179 # if HAVE_RAW_DECL_MBSINIT
180 _GL_WARN_ON_USE (mbsinit, "mbsinit is unportable - "
181 "use gnulib module mbsinit for portability");
186 /* Convert a multibyte character to a wide character. */
188 # if @REPLACE_MBRTOWC@
189 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
191 # define mbrtowc rpl_mbrtowc
193 _GL_FUNCDECL_RPL (mbrtowc, size_t,
194 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
195 _GL_CXXALIAS_RPL (mbrtowc, size_t,
196 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
199 _GL_FUNCDECL_SYS (mbrtowc, size_t,
200 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
202 _GL_CXXALIAS_SYS (mbrtowc, size_t,
203 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
205 _GL_CXXALIASWARN (mbrtowc);
206 #elif defined GNULIB_POSIXCHECK
208 # if HAVE_RAW_DECL_MBRTOWC
209 _GL_WARN_ON_USE (mbrtowc, "mbrtowc is unportable - "
210 "use gnulib module mbrtowc for portability");
215 /* Recognize a multibyte character. */
217 # if @REPLACE_MBRLEN@
218 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
220 # define mbrlen rpl_mbrlen
222 _GL_FUNCDECL_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
223 _GL_CXXALIAS_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
226 _GL_FUNCDECL_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
228 _GL_CXXALIAS_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
230 _GL_CXXALIASWARN (mbrlen);
231 #elif defined GNULIB_POSIXCHECK
233 # if HAVE_RAW_DECL_MBRLEN
234 _GL_WARN_ON_USE (mbrlen, "mbrlen is unportable - "
235 "use gnulib module mbrlen for portability");
240 /* Convert a string to a wide string. */
241 #if @GNULIB_MBSRTOWCS@
242 # if @REPLACE_MBSRTOWCS@
243 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
245 # define mbsrtowcs rpl_mbsrtowcs
247 _GL_FUNCDECL_RPL (mbsrtowcs, size_t,
248 (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
249 _GL_ARG_NONNULL ((2)));
250 _GL_CXXALIAS_RPL (mbsrtowcs, size_t,
251 (wchar_t *dest, const char **srcp, size_t len,
254 # if !@HAVE_MBSRTOWCS@
255 _GL_FUNCDECL_SYS (mbsrtowcs, size_t,
256 (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
257 _GL_ARG_NONNULL ((2)));
259 _GL_CXXALIAS_SYS (mbsrtowcs, size_t,
260 (wchar_t *dest, const char **srcp, size_t len,
263 _GL_CXXALIASWARN (mbsrtowcs);
264 #elif defined GNULIB_POSIXCHECK
266 # if HAVE_RAW_DECL_MBSRTOWCS
267 _GL_WARN_ON_USE (mbsrtowcs, "mbsrtowcs is unportable - "
268 "use gnulib module mbsrtowcs for portability");
273 /* Convert a string to a wide string. */
274 #if @GNULIB_MBSNRTOWCS@
275 # if @REPLACE_MBSNRTOWCS@
276 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
278 # define mbsnrtowcs rpl_mbsnrtowcs
280 _GL_FUNCDECL_RPL (mbsnrtowcs, size_t,
281 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
283 _GL_ARG_NONNULL ((2)));
284 _GL_CXXALIAS_RPL (mbsnrtowcs, size_t,
285 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
288 # if !@HAVE_MBSNRTOWCS@
289 _GL_FUNCDECL_SYS (mbsnrtowcs, size_t,
290 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
292 _GL_ARG_NONNULL ((2)));
294 _GL_CXXALIAS_SYS (mbsnrtowcs, size_t,
295 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
298 _GL_CXXALIASWARN (mbsnrtowcs);
299 #elif defined GNULIB_POSIXCHECK
301 # if HAVE_RAW_DECL_MBSNRTOWCS
302 _GL_WARN_ON_USE (mbsnrtowcs, "mbsnrtowcs is unportable - "
303 "use gnulib module mbsnrtowcs for portability");
308 /* Convert a wide character to a multibyte character. */
310 # if @REPLACE_WCRTOMB@
311 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
313 # define wcrtomb rpl_wcrtomb
315 _GL_FUNCDECL_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
316 _GL_CXXALIAS_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
319 _GL_FUNCDECL_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
321 _GL_CXXALIAS_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
323 _GL_CXXALIASWARN (wcrtomb);
324 #elif defined GNULIB_POSIXCHECK
326 # if HAVE_RAW_DECL_WCRTOMB
327 _GL_WARN_ON_USE (wcrtomb, "wcrtomb is unportable - "
328 "use gnulib module wcrtomb for portability");
333 /* Convert a wide string to a string. */
334 #if @GNULIB_WCSRTOMBS@
335 # if @REPLACE_WCSRTOMBS@
336 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
338 # define wcsrtombs rpl_wcsrtombs
340 _GL_FUNCDECL_RPL (wcsrtombs, size_t,
341 (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
342 _GL_ARG_NONNULL ((2)));
343 _GL_CXXALIAS_RPL (wcsrtombs, size_t,
344 (char *dest, const wchar_t **srcp, size_t len,
347 # if !@HAVE_WCSRTOMBS@
348 _GL_FUNCDECL_SYS (wcsrtombs, size_t,
349 (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
350 _GL_ARG_NONNULL ((2)));
352 _GL_CXXALIAS_SYS (wcsrtombs, size_t,
353 (char *dest, const wchar_t **srcp, size_t len,
356 _GL_CXXALIASWARN (wcsrtombs);
357 #elif defined GNULIB_POSIXCHECK
359 # if HAVE_RAW_DECL_WCSRTOMBS
360 _GL_WARN_ON_USE (wcsrtombs, "wcsrtombs is unportable - "
361 "use gnulib module wcsrtombs for portability");
366 /* Convert a wide string to a string. */
367 #if @GNULIB_WCSNRTOMBS@
368 # if @REPLACE_WCSNRTOMBS@
369 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
371 # define wcsnrtombs rpl_wcsnrtombs
373 _GL_FUNCDECL_RPL (wcsnrtombs, size_t,
374 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
376 _GL_ARG_NONNULL ((2)));
377 _GL_CXXALIAS_RPL (wcsnrtombs, size_t,
378 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
381 # if !@HAVE_WCSNRTOMBS@
382 _GL_FUNCDECL_SYS (wcsnrtombs, size_t,
383 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
385 _GL_ARG_NONNULL ((2)));
387 _GL_CXXALIAS_SYS (wcsnrtombs, size_t,
388 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
391 _GL_CXXALIASWARN (wcsnrtombs);
392 #elif defined GNULIB_POSIXCHECK
394 # if HAVE_RAW_DECL_WCSNRTOMBS
395 _GL_WARN_ON_USE (wcsnrtombs, "wcsnrtombs is unportable - "
396 "use gnulib module wcsnrtombs for portability");
401 /* Return the number of screen columns needed for WC. */
403 # if @REPLACE_WCWIDTH@
404 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
406 # define wcwidth rpl_wcwidth
408 _GL_FUNCDECL_RPL (wcwidth, int, (wchar_t));
409 _GL_CXXALIAS_RPL (wcwidth, int, (wchar_t));
411 # if !@HAVE_DECL_WCWIDTH@
412 /* wcwidth exists but is not declared. */
413 _GL_FUNCDECL_SYS (wcwidth, int, (wchar_t));
415 _GL_CXXALIAS_SYS (wcwidth, int, (wchar_t));
417 _GL_CXXALIASWARN (wcwidth);
418 #elif defined GNULIB_POSIXCHECK
420 # if HAVE_RAW_DECL_WCWIDTH
421 _GL_WARN_ON_USE (wcwidth, "wcwidth is unportable - "
422 "use gnulib module wcwidth for portability");
427 #endif /* _GL_WCHAR_H */
428 #endif /* _GL_WCHAR_H */