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 3, 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 __need_wint_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 glibc and 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>.
59 But avoid namespace pollution on glibc systems. */
66 /* Include the original <wchar.h> if it exists.
67 Some builds of uClibc lack it. */
68 /* The include_next requires a split double-inclusion guard. */
70 # @INCLUDE_NEXT@ @NEXT_WCHAR_H@
73 #undef _GL_ALREADY_INCLUDING_WCHAR_H
78 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
80 /* The definition of _GL_ARG_NONNULL is copied here. */
82 /* The definition of _GL_WARN_ON_USE is copied here. */
85 /* Define wint_t and WEOF. (Also done in wctype.in.h.) */
86 #if !@HAVE_WINT_T@ && !defined wint_t
93 # define WEOF ((wint_t) -1)
98 /* Override mbstate_t if it is too small.
99 On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
100 implementing mbrtowc for encodings like UTF-8. */
101 #if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
102 typedef int rpl_mbstate_t
;
104 # define mbstate_t rpl_mbstate_t
105 # define GNULIB_defined_mbstate_t 1
109 /* Convert a single-byte character to a wide character. */
112 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
114 # define btowc rpl_btowc
116 _GL_FUNCDECL_RPL (btowc
, wint_t, (int c
));
117 _GL_CXXALIAS_RPL (btowc
, wint_t, (int c
));
120 _GL_FUNCDECL_SYS (btowc
, wint_t, (int c
));
122 _GL_CXXALIAS_SYS (btowc
, wint_t, (int c
));
124 _GL_CXXALIASWARN (btowc
);
125 #elif defined GNULIB_POSIXCHECK
127 # if HAVE_RAW_DECL_BTOWC
128 _GL_WARN_ON_USE (btowc
, "btowc is unportable - "
129 "use gnulib module btowc for portability");
134 /* Convert a wide character to a single-byte character. */
137 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
139 # define wctob rpl_wctob
141 _GL_FUNCDECL_RPL (wctob
, int, (wint_t wc
));
142 _GL_CXXALIAS_RPL (wctob
, int, (wint_t wc
));
144 # if !defined wctob && !@HAVE_DECL_WCTOB@
145 /* wctob is provided by gnulib, or wctob exists but is not declared. */
146 _GL_FUNCDECL_SYS (wctob
, int, (wint_t wc
));
148 _GL_CXXALIAS_SYS (wctob
, int, (wint_t wc
));
150 _GL_CXXALIASWARN (wctob
);
151 #elif defined GNULIB_POSIXCHECK
153 # if HAVE_RAW_DECL_WCTOB
154 _GL_WARN_ON_USE (wctob
, "wctob is unportable - "
155 "use gnulib module wctob for portability");
160 /* Test whether *PS is in the initial state. */
162 # if @REPLACE_MBSINIT@
163 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
165 # define mbsinit rpl_mbsinit
167 _GL_FUNCDECL_RPL (mbsinit
, int, (const mbstate_t *ps
));
168 _GL_CXXALIAS_RPL (mbsinit
, int, (const mbstate_t *ps
));
171 _GL_FUNCDECL_SYS (mbsinit
, int, (const mbstate_t *ps
));
173 _GL_CXXALIAS_SYS (mbsinit
, int, (const mbstate_t *ps
));
175 _GL_CXXALIASWARN (mbsinit
);
176 #elif defined GNULIB_POSIXCHECK
178 # if HAVE_RAW_DECL_MBSINIT
179 _GL_WARN_ON_USE (mbsinit
, "mbsinit is unportable - "
180 "use gnulib module mbsinit for portability");
185 /* Convert a multibyte character to a wide character. */
187 # if @REPLACE_MBRTOWC@
188 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
190 # define mbrtowc rpl_mbrtowc
192 _GL_FUNCDECL_RPL (mbrtowc
, size_t,
193 (wchar_t *pwc
, const char *s
, size_t n
, mbstate_t *ps
));
194 _GL_CXXALIAS_RPL (mbrtowc
, size_t,
195 (wchar_t *pwc
, const char *s
, size_t n
, mbstate_t *ps
));
198 _GL_FUNCDECL_SYS (mbrtowc
, size_t,
199 (wchar_t *pwc
, const char *s
, size_t n
, mbstate_t *ps
));
201 _GL_CXXALIAS_SYS (mbrtowc
, size_t,
202 (wchar_t *pwc
, const char *s
, size_t n
, mbstate_t *ps
));
204 _GL_CXXALIASWARN (mbrtowc
);
205 #elif defined GNULIB_POSIXCHECK
207 # if HAVE_RAW_DECL_MBRTOWC
208 _GL_WARN_ON_USE (mbrtowc
, "mbrtowc is unportable - "
209 "use gnulib module mbrtowc for portability");
214 /* Recognize a multibyte character. */
216 # if @REPLACE_MBRLEN@
217 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
219 # define mbrlen rpl_mbrlen
221 _GL_FUNCDECL_RPL (mbrlen
, size_t, (const char *s
, size_t n
, mbstate_t *ps
));
222 _GL_CXXALIAS_RPL (mbrlen
, size_t, (const char *s
, size_t n
, mbstate_t *ps
));
225 _GL_FUNCDECL_SYS (mbrlen
, size_t, (const char *s
, size_t n
, mbstate_t *ps
));
227 _GL_CXXALIAS_SYS (mbrlen
, size_t, (const char *s
, size_t n
, mbstate_t *ps
));
229 _GL_CXXALIASWARN (mbrlen
);
230 #elif defined GNULIB_POSIXCHECK
232 # if HAVE_RAW_DECL_MBRLEN
233 _GL_WARN_ON_USE (mbrlen
, "mbrlen is unportable - "
234 "use gnulib module mbrlen for portability");
239 /* Convert a string to a wide string. */
240 #if @GNULIB_MBSRTOWCS@
241 # if @REPLACE_MBSRTOWCS@
242 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
244 # define mbsrtowcs rpl_mbsrtowcs
246 _GL_FUNCDECL_RPL (mbsrtowcs
, size_t,
247 (wchar_t *dest
, const char **srcp
, size_t len
, mbstate_t *ps
)
248 _GL_ARG_NONNULL ((2)));
249 _GL_CXXALIAS_RPL (mbsrtowcs
, size_t,
250 (wchar_t *dest
, const char **srcp
, size_t len
,
253 # if !@HAVE_MBSRTOWCS@
254 _GL_FUNCDECL_SYS (mbsrtowcs
, size_t,
255 (wchar_t *dest
, const char **srcp
, size_t len
, mbstate_t *ps
)
256 _GL_ARG_NONNULL ((2)));
258 _GL_CXXALIAS_SYS (mbsrtowcs
, size_t,
259 (wchar_t *dest
, const char **srcp
, size_t len
,
262 _GL_CXXALIASWARN (mbsrtowcs
);
263 #elif defined GNULIB_POSIXCHECK
265 # if HAVE_RAW_DECL_MBSRTOWCS
266 _GL_WARN_ON_USE (mbsrtowcs
, "mbsrtowcs is unportable - "
267 "use gnulib module mbsrtowcs for portability");
272 /* Convert a string to a wide string. */
273 #if @GNULIB_MBSNRTOWCS@
274 # if @REPLACE_MBSNRTOWCS@
275 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
277 # define mbsnrtowcs rpl_mbsnrtowcs
279 _GL_FUNCDECL_RPL (mbsnrtowcs
, size_t,
280 (wchar_t *dest
, const char **srcp
, size_t srclen
, size_t len
,
282 _GL_ARG_NONNULL ((2)));
283 _GL_CXXALIAS_RPL (mbsnrtowcs
, size_t,
284 (wchar_t *dest
, const char **srcp
, size_t srclen
, size_t len
,
287 # if !@HAVE_MBSNRTOWCS@
288 _GL_FUNCDECL_SYS (mbsnrtowcs
, size_t,
289 (wchar_t *dest
, const char **srcp
, size_t srclen
, size_t len
,
291 _GL_ARG_NONNULL ((2)));
293 _GL_CXXALIAS_SYS (mbsnrtowcs
, size_t,
294 (wchar_t *dest
, const char **srcp
, size_t srclen
, size_t len
,
297 _GL_CXXALIASWARN (mbsnrtowcs
);
298 #elif defined GNULIB_POSIXCHECK
300 # if HAVE_RAW_DECL_MBSNRTOWCS
301 _GL_WARN_ON_USE (mbsnrtowcs
, "mbsnrtowcs is unportable - "
302 "use gnulib module mbsnrtowcs for portability");
307 /* Convert a wide character to a multibyte character. */
309 # if @REPLACE_WCRTOMB@
310 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
312 # define wcrtomb rpl_wcrtomb
314 _GL_FUNCDECL_RPL (wcrtomb
, size_t, (char *s
, wchar_t wc
, mbstate_t *ps
));
315 _GL_CXXALIAS_RPL (wcrtomb
, size_t, (char *s
, wchar_t wc
, mbstate_t *ps
));
318 _GL_FUNCDECL_SYS (wcrtomb
, size_t, (char *s
, wchar_t wc
, mbstate_t *ps
));
320 _GL_CXXALIAS_SYS (wcrtomb
, size_t, (char *s
, wchar_t wc
, mbstate_t *ps
));
322 _GL_CXXALIASWARN (wcrtomb
);
323 #elif defined GNULIB_POSIXCHECK
325 # if HAVE_RAW_DECL_WCRTOMB
326 _GL_WARN_ON_USE (wcrtomb
, "wcrtomb is unportable - "
327 "use gnulib module wcrtomb for portability");
332 /* Convert a wide string to a string. */
333 #if @GNULIB_WCSRTOMBS@
334 # if @REPLACE_WCSRTOMBS@
335 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
337 # define wcsrtombs rpl_wcsrtombs
339 _GL_FUNCDECL_RPL (wcsrtombs
, size_t,
340 (char *dest
, const wchar_t **srcp
, size_t len
, mbstate_t *ps
)
341 _GL_ARG_NONNULL ((2)));
342 _GL_CXXALIAS_RPL (wcsrtombs
, size_t,
343 (char *dest
, const wchar_t **srcp
, size_t len
,
346 # if !@HAVE_WCSRTOMBS@
347 _GL_FUNCDECL_SYS (wcsrtombs
, size_t,
348 (char *dest
, const wchar_t **srcp
, size_t len
, mbstate_t *ps
)
349 _GL_ARG_NONNULL ((2)));
351 _GL_CXXALIAS_SYS (wcsrtombs
, size_t,
352 (char *dest
, const wchar_t **srcp
, size_t len
,
355 _GL_CXXALIASWARN (wcsrtombs
);
356 #elif defined GNULIB_POSIXCHECK
358 # if HAVE_RAW_DECL_WCSRTOMBS
359 _GL_WARN_ON_USE (wcsrtombs
, "wcsrtombs is unportable - "
360 "use gnulib module wcsrtombs for portability");
365 /* Convert a wide string to a string. */
366 #if @GNULIB_WCSNRTOMBS@
367 # if @REPLACE_WCSNRTOMBS@
368 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
370 # define wcsnrtombs rpl_wcsnrtombs
372 _GL_FUNCDECL_RPL (wcsnrtombs
, size_t,
373 (char *dest
, const wchar_t **srcp
, size_t srclen
, size_t len
,
375 _GL_ARG_NONNULL ((2)));
376 _GL_CXXALIAS_RPL (wcsnrtombs
, size_t,
377 (char *dest
, const wchar_t **srcp
, size_t srclen
, size_t len
,
380 # if !@HAVE_WCSNRTOMBS@
381 _GL_FUNCDECL_SYS (wcsnrtombs
, size_t,
382 (char *dest
, const wchar_t **srcp
, size_t srclen
, size_t len
,
384 _GL_ARG_NONNULL ((2)));
386 _GL_CXXALIAS_SYS (wcsnrtombs
, size_t,
387 (char *dest
, const wchar_t **srcp
, size_t srclen
, size_t len
,
390 _GL_CXXALIASWARN (wcsnrtombs
);
391 #elif defined GNULIB_POSIXCHECK
393 # if HAVE_RAW_DECL_WCSNRTOMBS
394 _GL_WARN_ON_USE (wcsnrtombs
, "wcsnrtombs is unportable - "
395 "use gnulib module wcsnrtombs for portability");
400 /* Return the number of screen columns needed for WC. */
402 # if @REPLACE_WCWIDTH@
403 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
405 # define wcwidth rpl_wcwidth
407 _GL_FUNCDECL_RPL (wcwidth
, int, (wchar_t));
408 _GL_CXXALIAS_RPL (wcwidth
, int, (wchar_t));
410 # if !@HAVE_DECL_WCWIDTH@
411 /* wcwidth exists but is not declared. */
412 _GL_FUNCDECL_SYS (wcwidth
, int, (wchar_t));
414 _GL_CXXALIAS_SYS (wcwidth
, int, (wchar_t));
416 _GL_CXXALIASWARN (wcwidth
);
417 #elif defined GNULIB_POSIXCHECK
419 # if HAVE_RAW_DECL_WCWIDTH
420 _GL_WARN_ON_USE (wcwidth
, "wcwidth is unportable - "
421 "use gnulib module wcwidth for portability");
426 #endif /* _GL_WCHAR_H */
427 #endif /* _GL_WCHAR_H */