Temporarily fix `unistr.in.h' to allow compilation with `-Wundef'.
[bpt/guile.git] / lib / wchar.in.h
CommitLineData
e65fc94b
LC
1/* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
2
61cd9dc9 3 Copyright (C) 2007-2010 Free Software Foundation, Inc.
e65fc94b
LC
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser 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
aa7a939c 29#if __GNUC__ >= 3
e65fc94b 30@PRAGMA_SYSTEM_HEADER@
aa7a939c 31#endif
0f00f2c3 32@PRAGMA_COLUMNS@
e65fc94b 33
61cd9dc9 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
f240aacb 35/* Special invocation convention:
61cd9dc9 36 - Inside glibc and uClibc header files.
f240aacb
LC
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. */
e65fc94b
LC
46
47#@INCLUDE_NEXT@ @NEXT_WCHAR_H@
48
49#else
50/* Normal invocation convention. */
51
52#ifndef _GL_WCHAR_H
53
f240aacb
LC
54#define _GL_ALREADY_INCLUDING_WCHAR_H
55
0f00f2c3
LC
56#if @HAVE_FEATURES_H@
57# include <features.h> /* for __GLIBC__ */
58#endif
59
e65fc94b
LC
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
61cd9dc9
LC
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
e65fc94b
LC
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
f240aacb
LC
78#undef _GL_ALREADY_INCLUDING_WCHAR_H
79
e65fc94b
LC
80#ifndef _GL_WCHAR_H
81#define _GL_WCHAR_H
82
f4c79b3c
LC
83/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
84
1cd4fffc
LC
85/* The definition of _GL_ARG_NONNULL is copied here. */
86
61cd9dc9
LC
87/* The definition of _GL_WARN_ON_USE is copied here. */
88
e65fc94b 89
a927b6c1 90/* Define wint_t and WEOF. (Also done in wctype.in.h.) */
aa7a939c
LC
91#if !@HAVE_WINT_T@ && !defined wint_t
92# define wint_t int
4a462e35
NJ
93# ifndef WEOF
94# define WEOF -1
95# endif
a927b6c1
LC
96#else
97# ifndef WEOF
98# define WEOF ((wint_t) -1)
99# endif
4a462e35
NJ
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@
107typedef 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@
f4c79b3c
LC
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));
4a462e35 128# endif
f4c79b3c 129_GL_CXXALIASWARN (btowc);
4a462e35
NJ
130#elif defined GNULIB_POSIXCHECK
131# undef btowc
61cd9dc9
LC
132# if HAVE_RAW_DECL_BTOWC
133_GL_WARN_ON_USE (btowc, "btowc is unportable - "
134 "use gnulib module btowc for portability");
135# endif
4a462e35
NJ
136#endif
137
138
139/* Convert a wide character to a single-byte character. */
140#if @GNULIB_WCTOB@
141# if @REPLACE_WCTOB@
f4c79b3c
LC
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@
4a462e35 150/* wctob is provided by gnulib, or wctob exists but is not declared. */
f4c79b3c
LC
151_GL_FUNCDECL_SYS (wctob, int, (wint_t wc));
152# endif
153_GL_CXXALIAS_SYS (wctob, int, (wint_t wc));
4a462e35 154# endif
f4c79b3c 155_GL_CXXALIASWARN (wctob);
4a462e35
NJ
156#elif defined GNULIB_POSIXCHECK
157# undef wctob
61cd9dc9
LC
158# if HAVE_RAW_DECL_WCTOB
159_GL_WARN_ON_USE (wctob, "wctob is unportable - "
160 "use gnulib module wctob for portability");
161# endif
4a462e35
NJ
162#endif
163
164
165/* Test whether *PS is in the initial state. */
166#if @GNULIB_MBSINIT@
167# if @REPLACE_MBSINIT@
f4c79b3c
LC
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));
4a462e35 179# endif
f4c79b3c 180_GL_CXXALIASWARN (mbsinit);
4a462e35
NJ
181#elif defined GNULIB_POSIXCHECK
182# undef mbsinit
61cd9dc9
LC
183# if HAVE_RAW_DECL_MBSINIT
184_GL_WARN_ON_USE (mbsinit, "mbsinit is unportable - "
185 "use gnulib module mbsinit for portability");
186# endif
4a462e35
NJ
187#endif
188
189
190/* Convert a multibyte character to a wide character. */
191#if @GNULIB_MBRTOWC@
192# if @REPLACE_MBRTOWC@
f4c79b3c
LC
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));
4a462e35 208# endif
f4c79b3c 209_GL_CXXALIASWARN (mbrtowc);
4a462e35
NJ
210#elif defined GNULIB_POSIXCHECK
211# undef mbrtowc
61cd9dc9
LC
212# if HAVE_RAW_DECL_MBRTOWC
213_GL_WARN_ON_USE (mbrtowc, "mbrtowc is unportable - "
214 "use gnulib module mbrtowc for portability");
215# endif
4a462e35
NJ
216#endif
217
218
219/* Recognize a multibyte character. */
220#if @GNULIB_MBRLEN@
221# if @REPLACE_MBRLEN@
f4c79b3c
LC
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));
4a462e35 233# endif
f4c79b3c 234_GL_CXXALIASWARN (mbrlen);
4a462e35
NJ
235#elif defined GNULIB_POSIXCHECK
236# undef mbrlen
61cd9dc9
LC
237# if HAVE_RAW_DECL_MBRLEN
238_GL_WARN_ON_USE (mbrlen, "mbrlen is unportable - "
239 "use gnulib module mbrlen for portability");
240# endif
4a462e35
NJ
241#endif
242
243
244/* Convert a string to a wide string. */
245#if @GNULIB_MBSRTOWCS@
246# if @REPLACE_MBSRTOWCS@
f4c79b3c
LC
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));
4a462e35 266# endif
f4c79b3c 267_GL_CXXALIASWARN (mbsrtowcs);
4a462e35
NJ
268#elif defined GNULIB_POSIXCHECK
269# undef mbsrtowcs
61cd9dc9
LC
270# if HAVE_RAW_DECL_MBSRTOWCS
271_GL_WARN_ON_USE (mbsrtowcs, "mbsrtowcs is unportable - "
272 "use gnulib module mbsrtowcs for portability");
273# endif
4a462e35
NJ
274#endif
275
276
277/* Convert a string to a wide string. */
278#if @GNULIB_MBSNRTOWCS@
279# if @REPLACE_MBSNRTOWCS@
f4c79b3c
LC
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));
4a462e35 301# endif
f4c79b3c 302_GL_CXXALIASWARN (mbsnrtowcs);
4a462e35
NJ
303#elif defined GNULIB_POSIXCHECK
304# undef mbsnrtowcs
61cd9dc9
LC
305# if HAVE_RAW_DECL_MBSNRTOWCS
306_GL_WARN_ON_USE (mbsnrtowcs, "mbsnrtowcs is unportable - "
307 "use gnulib module mbsnrtowcs for portability");
308# endif
4a462e35
NJ
309#endif
310
311
312/* Convert a wide character to a multibyte character. */
313#if @GNULIB_WCRTOMB@
314# if @REPLACE_WCRTOMB@
f4c79b3c
LC
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));
4a462e35 326# endif
f4c79b3c 327_GL_CXXALIASWARN (wcrtomb);
4a462e35
NJ
328#elif defined GNULIB_POSIXCHECK
329# undef wcrtomb
61cd9dc9
LC
330# if HAVE_RAW_DECL_WCRTOMB
331_GL_WARN_ON_USE (wcrtomb, "wcrtomb is unportable - "
332 "use gnulib module wcrtomb for portability");
333# endif
4a462e35
NJ
334#endif
335
336
337/* Convert a wide string to a string. */
338#if @GNULIB_WCSRTOMBS@
339# if @REPLACE_WCSRTOMBS@
f4c79b3c
LC
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));
4a462e35 359# endif
f4c79b3c 360_GL_CXXALIASWARN (wcsrtombs);
4a462e35
NJ
361#elif defined GNULIB_POSIXCHECK
362# undef wcsrtombs
61cd9dc9
LC
363# if HAVE_RAW_DECL_WCSRTOMBS
364_GL_WARN_ON_USE (wcsrtombs, "wcsrtombs is unportable - "
365 "use gnulib module wcsrtombs for portability");
366# endif
4a462e35
NJ
367#endif
368
369
370/* Convert a wide string to a string. */
371#if @GNULIB_WCSNRTOMBS@
f240aacb 372# if @REPLACE_WCSNRTOMBS@
f4c79b3c
LC
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));
4a462e35 394# endif
f4c79b3c 395_GL_CXXALIASWARN (wcsnrtombs);
4a462e35
NJ
396#elif defined GNULIB_POSIXCHECK
397# undef wcsnrtombs
61cd9dc9
LC
398# if HAVE_RAW_DECL_WCSNRTOMBS
399_GL_WARN_ON_USE (wcsnrtombs, "wcsnrtombs is unportable - "
400 "use gnulib module wcsnrtombs for portability");
401# endif
aa7a939c
LC
402#endif
403
404
e65fc94b
LC
405/* Return the number of screen columns needed for WC. */
406#if @GNULIB_WCWIDTH@
407# if @REPLACE_WCWIDTH@
f4c79b3c
LC
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));
e65fc94b 414# else
a927b6c1 415# if !@HAVE_DECL_WCWIDTH@
e65fc94b 416/* wcwidth exists but is not declared. */
f4c79b3c 417_GL_FUNCDECL_SYS (wcwidth, int, (wchar_t));
e65fc94b 418# endif
f4c79b3c 419_GL_CXXALIAS_SYS (wcwidth, int, (wchar_t));
e65fc94b 420# endif
f4c79b3c 421_GL_CXXALIASWARN (wcwidth);
e65fc94b
LC
422#elif defined GNULIB_POSIXCHECK
423# undef wcwidth
61cd9dc9
LC
424# if HAVE_RAW_DECL_WCWIDTH
425_GL_WARN_ON_USE (wcwidth, "wcwidth is unportable - "
426 "use gnulib module wcwidth for portability");
427# endif
e65fc94b
LC
428#endif
429
430
e65fc94b
LC
431#endif /* _GL_WCHAR_H */
432#endif /* _GL_WCHAR_H */
433#endif