1 /* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
3 Copyright (C) 2007-2009 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@
33 #if defined __need_mbstate_t || (defined __hpux && ((defined _INTTYPES_INCLUDED && !defined strtoimax) || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) || defined _GL_ALREADY_INCLUDING_WCHAR_H
34 /* Special invocation convention:
35 - Inside uClibc header files.
36 - On HP-UX 11.00 we have a sequence of nested includes
37 <wchar.h> -> <stdlib.h> -> <stdint.h>, and the latter includes <wchar.h>,
38 once indirectly <stdint.h> -> <sys/types.h> -> <inttypes.h> -> <wchar.h>
39 and once directly. In both situations 'wint_t' is not yet defined,
40 therefore we cannot provide the function overrides; instead include only
41 the system's <wchar.h>.
42 - On IRIX 6.5, similarly, we have an include <wchar.h> -> <wctype.h>, and
43 the latter includes <wchar.h>. But here, we have no way to detect whether
44 <wctype.h> is completely included or is still being included. */
46 #@INCLUDE_NEXT@ @NEXT_WCHAR_H@
49 /* Normal invocation convention. */
53 #define _GL_ALREADY_INCLUDING_WCHAR_H
55 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
57 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
58 included before <wchar.h>. */
63 /* Include the original <wchar.h> if it exists.
64 Some builds of uClibc lack it. */
65 /* The include_next requires a split double-inclusion guard. */
67 # @INCLUDE_NEXT@ @NEXT_WCHAR_H@
70 #undef _GL_ALREADY_INCLUDING_WCHAR_H
75 /* The definition of GL_LINK_WARNING is copied here. */
77 /* The definition of _GL_ARG_NONNULL is copied here. */
84 /* Define wint_t. (Also done in wctype.in.h.) */
85 #if !@HAVE_WINT_T@ && !defined wint_t
93 /* Override mbstate_t if it is too small.
94 On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
95 implementing mbrtowc for encodings like UTF-8. */
96 #if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
97 typedef int rpl_mbstate_t;
99 # define mbstate_t rpl_mbstate_t
100 # define GNULIB_defined_mbstate_t 1
104 /* Convert a single-byte character to a wide character. */
108 # define btowc rpl_btowc
110 # if !@HAVE_BTOWC@ || @REPLACE_BTOWC@
111 extern wint_t btowc (int c);
113 #elif defined GNULIB_POSIXCHECK
116 (GL_LINK_WARNING ("btowc is unportable - " \
117 "use gnulib module btowc for portability"), \
122 /* Convert a wide character to a single-byte character. */
126 # define wctob rpl_wctob
128 # if (!defined wctob && !@HAVE_DECL_WCTOB@) || @REPLACE_WCTOB@
129 /* wctob is provided by gnulib, or wctob exists but is not declared. */
130 extern int wctob (wint_t wc);
132 #elif defined GNULIB_POSIXCHECK
135 (GL_LINK_WARNING ("wctob is unportable - " \
136 "use gnulib module wctob for portability"), \
141 /* Test whether *PS is in the initial state. */
143 # if @REPLACE_MBSINIT@
145 # define mbsinit rpl_mbsinit
147 # if !@HAVE_MBSINIT@ || @REPLACE_MBSINIT@
148 extern int mbsinit (const mbstate_t *ps);
150 #elif defined GNULIB_POSIXCHECK
152 # define mbsinit(p) \
153 (GL_LINK_WARNING ("mbsinit is unportable - " \
154 "use gnulib module mbsinit for portability"), \
159 /* Convert a multibyte character to a wide character. */
161 # if @REPLACE_MBRTOWC@
163 # define mbrtowc rpl_mbrtowc
165 # if !@HAVE_MBRTOWC@ || @REPLACE_MBRTOWC@
166 extern size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
168 #elif defined GNULIB_POSIXCHECK
170 # define mbrtowc(w,s,n,p) \
171 (GL_LINK_WARNING ("mbrtowc is unportable - " \
172 "use gnulib module mbrtowc for portability"), \
173 mbrtowc (w, s, n, p))
177 /* Recognize a multibyte character. */
179 # if @REPLACE_MBRLEN@
181 # define mbrlen rpl_mbrlen
183 # if !@HAVE_MBRLEN@ || @REPLACE_MBRLEN@
184 extern size_t mbrlen (const char *s, size_t n, mbstate_t *ps);
186 #elif defined GNULIB_POSIXCHECK
188 # define mbrlen(s,n,p) \
189 (GL_LINK_WARNING ("mbrlen is unportable - " \
190 "use gnulib module mbrlen for portability"), \
195 /* Convert a string to a wide string. */
196 #if @GNULIB_MBSRTOWCS@
197 # if @REPLACE_MBSRTOWCS@
199 # define mbsrtowcs rpl_mbsrtowcs
201 # if !@HAVE_MBSRTOWCS@ || @REPLACE_MBSRTOWCS@
202 extern size_t mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
203 _GL_ARG_NONNULL ((2));
205 #elif defined GNULIB_POSIXCHECK
207 # define mbsrtowcs(d,s,l,p) \
208 (GL_LINK_WARNING ("mbsrtowcs is unportable - " \
209 "use gnulib module mbsrtowcs for portability"), \
210 mbsrtowcs (d, s, l, p))
214 /* Convert a string to a wide string. */
215 #if @GNULIB_MBSNRTOWCS@
216 # if @REPLACE_MBSNRTOWCS@
218 # define mbsnrtowcs rpl_mbsnrtowcs
220 # if !@HAVE_MBSNRTOWCS@ || @REPLACE_MBSNRTOWCS@
221 extern size_t mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps)
222 _GL_ARG_NONNULL ((2));
224 #elif defined GNULIB_POSIXCHECK
226 # define mbsnrtowcs(d,s,n,l,p) \
227 (GL_LINK_WARNING ("mbsnrtowcs is unportable - " \
228 "use gnulib module mbsnrtowcs for portability"), \
229 mbsnrtowcs (d, s, n, l, p))
233 /* Convert a wide character to a multibyte character. */
235 # if @REPLACE_WCRTOMB@
237 # define wcrtomb rpl_wcrtomb
239 # if !@HAVE_WCRTOMB@ || @REPLACE_WCRTOMB@
240 extern size_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps);
242 #elif defined GNULIB_POSIXCHECK
244 # define wcrtomb(s,w,p) \
245 (GL_LINK_WARNING ("wcrtomb is unportable - " \
246 "use gnulib module wcrtomb for portability"), \
251 /* Convert a wide string to a string. */
252 #if @GNULIB_WCSRTOMBS@
253 # if @REPLACE_WCSRTOMBS@
255 # define wcsrtombs rpl_wcsrtombs
257 # if !@HAVE_WCSRTOMBS@ || @REPLACE_WCSRTOMBS@
258 extern size_t wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
259 _GL_ARG_NONNULL ((2));
261 #elif defined GNULIB_POSIXCHECK
263 # define wcsrtombs(d,s,l,p) \
264 (GL_LINK_WARNING ("wcsrtombs is unportable - " \
265 "use gnulib module wcsrtombs for portability"), \
266 wcsrtombs (d, s, l, p))
270 /* Convert a wide string to a string. */
271 #if @GNULIB_WCSNRTOMBS@
272 # if @REPLACE_WCSNRTOMBS@
274 # define wcsnrtombs rpl_wcsnrtombs
276 # if !@HAVE_WCSNRTOMBS@ || @REPLACE_WCSNRTOMBS@
277 extern size_t wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps)
278 _GL_ARG_NONNULL ((2));
280 #elif defined GNULIB_POSIXCHECK
282 # define wcsnrtombs(d,s,n,l,p) \
283 (GL_LINK_WARNING ("wcsnrtombs is unportable - " \
284 "use gnulib module wcsnrtombs for portability"), \
285 wcsnrtombs (d, s, n, l, p))
289 /* Return the number of screen columns needed for WC. */
291 # if @REPLACE_WCWIDTH@
293 # define wcwidth rpl_wcwidth
294 extern int wcwidth (wchar_t);
296 # if !defined wcwidth && !@HAVE_DECL_WCWIDTH@
297 /* wcwidth exists but is not declared. */
298 extern int wcwidth (int /* actually wchar_t */);
301 #elif defined GNULIB_POSIXCHECK
303 # define wcwidth(w) \
304 (GL_LINK_WARNING ("wcwidth is unportable - " \
305 "use gnulib module wcwidth for portability"), \
314 #endif /* _GL_WCHAR_H */
315 #endif /* _GL_WCHAR_H */