Use Gnulib's `isnan' and `isinf' modules.
[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
e65fc94b 32
61cd9dc9 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
f240aacb 34/* Special invocation convention:
61cd9dc9 35 - Inside glibc and uClibc header files.
f240aacb
LC
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. */
e65fc94b
LC
45
46#@INCLUDE_NEXT@ @NEXT_WCHAR_H@
47
48#else
49/* Normal invocation convention. */
50
51#ifndef _GL_WCHAR_H
52
f240aacb
LC
53#define _GL_ALREADY_INCLUDING_WCHAR_H
54
e65fc94b
LC
55/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
56 <wchar.h>.
57 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
61cd9dc9
LC
58 included before <wchar.h>.
59 But avoid namespace pollution on glibc systems. */
60#ifndef __GLIBC__
61# include <stddef.h>
62# include <stdio.h>
63# include <time.h>
64#endif
e65fc94b
LC
65
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. */
69#if @HAVE_WCHAR_H@
70# @INCLUDE_NEXT@ @NEXT_WCHAR_H@
71#endif
72
f240aacb
LC
73#undef _GL_ALREADY_INCLUDING_WCHAR_H
74
e65fc94b
LC
75#ifndef _GL_WCHAR_H
76#define _GL_WCHAR_H
77
f4c79b3c
LC
78/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
79
1cd4fffc
LC
80/* The definition of _GL_ARG_NONNULL is copied here. */
81
61cd9dc9
LC
82/* The definition of _GL_WARN_ON_USE is copied here. */
83
e65fc94b 84
a927b6c1 85/* Define wint_t and WEOF. (Also done in wctype.in.h.) */
aa7a939c
LC
86#if !@HAVE_WINT_T@ && !defined wint_t
87# define wint_t int
4a462e35
NJ
88# ifndef WEOF
89# define WEOF -1
90# endif
a927b6c1
LC
91#else
92# ifndef WEOF
93# define WEOF ((wint_t) -1)
94# endif
4a462e35
NJ
95#endif
96
97
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@
102typedef int rpl_mbstate_t;
103# undef mbstate_t
104# define mbstate_t rpl_mbstate_t
105# define GNULIB_defined_mbstate_t 1
106#endif
107
108
109/* Convert a single-byte character to a wide character. */
110#if @GNULIB_BTOWC@
111# if @REPLACE_BTOWC@
f4c79b3c
LC
112# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
113# undef btowc
114# define btowc rpl_btowc
115# endif
116_GL_FUNCDECL_RPL (btowc, wint_t, (int c));
117_GL_CXXALIAS_RPL (btowc, wint_t, (int c));
118# else
119# if !@HAVE_BTOWC@
120_GL_FUNCDECL_SYS (btowc, wint_t, (int c));
121# endif
122_GL_CXXALIAS_SYS (btowc, wint_t, (int c));
4a462e35 123# endif
f4c79b3c 124_GL_CXXALIASWARN (btowc);
4a462e35
NJ
125#elif defined GNULIB_POSIXCHECK
126# undef btowc
61cd9dc9
LC
127# if HAVE_RAW_DECL_BTOWC
128_GL_WARN_ON_USE (btowc, "btowc is unportable - "
129 "use gnulib module btowc for portability");
130# endif
4a462e35
NJ
131#endif
132
133
134/* Convert a wide character to a single-byte character. */
135#if @GNULIB_WCTOB@
136# if @REPLACE_WCTOB@
f4c79b3c
LC
137# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
138# undef wctob
139# define wctob rpl_wctob
140# endif
141_GL_FUNCDECL_RPL (wctob, int, (wint_t wc));
142_GL_CXXALIAS_RPL (wctob, int, (wint_t wc));
143# else
144# if !defined wctob && !@HAVE_DECL_WCTOB@
4a462e35 145/* wctob is provided by gnulib, or wctob exists but is not declared. */
f4c79b3c
LC
146_GL_FUNCDECL_SYS (wctob, int, (wint_t wc));
147# endif
148_GL_CXXALIAS_SYS (wctob, int, (wint_t wc));
4a462e35 149# endif
f4c79b3c 150_GL_CXXALIASWARN (wctob);
4a462e35
NJ
151#elif defined GNULIB_POSIXCHECK
152# undef wctob
61cd9dc9
LC
153# if HAVE_RAW_DECL_WCTOB
154_GL_WARN_ON_USE (wctob, "wctob is unportable - "
155 "use gnulib module wctob for portability");
156# endif
4a462e35
NJ
157#endif
158
159
160/* Test whether *PS is in the initial state. */
161#if @GNULIB_MBSINIT@
162# if @REPLACE_MBSINIT@
f4c79b3c
LC
163# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
164# undef mbsinit
165# define mbsinit rpl_mbsinit
166# endif
167_GL_FUNCDECL_RPL (mbsinit, int, (const mbstate_t *ps));
168_GL_CXXALIAS_RPL (mbsinit, int, (const mbstate_t *ps));
169# else
170# if !@HAVE_MBSINIT@
171_GL_FUNCDECL_SYS (mbsinit, int, (const mbstate_t *ps));
172# endif
173_GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps));
4a462e35 174# endif
f4c79b3c 175_GL_CXXALIASWARN (mbsinit);
4a462e35
NJ
176#elif defined GNULIB_POSIXCHECK
177# undef mbsinit
61cd9dc9
LC
178# if HAVE_RAW_DECL_MBSINIT
179_GL_WARN_ON_USE (mbsinit, "mbsinit is unportable - "
180 "use gnulib module mbsinit for portability");
181# endif
4a462e35
NJ
182#endif
183
184
185/* Convert a multibyte character to a wide character. */
186#if @GNULIB_MBRTOWC@
187# if @REPLACE_MBRTOWC@
f4c79b3c
LC
188# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
189# undef mbrtowc
190# define mbrtowc rpl_mbrtowc
191# endif
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));
196# else
197# if !@HAVE_MBRTOWC@
198_GL_FUNCDECL_SYS (mbrtowc, size_t,
199 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
200# endif
201_GL_CXXALIAS_SYS (mbrtowc, size_t,
202 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
4a462e35 203# endif
f4c79b3c 204_GL_CXXALIASWARN (mbrtowc);
4a462e35
NJ
205#elif defined GNULIB_POSIXCHECK
206# undef mbrtowc
61cd9dc9
LC
207# if HAVE_RAW_DECL_MBRTOWC
208_GL_WARN_ON_USE (mbrtowc, "mbrtowc is unportable - "
209 "use gnulib module mbrtowc for portability");
210# endif
4a462e35
NJ
211#endif
212
213
214/* Recognize a multibyte character. */
215#if @GNULIB_MBRLEN@
216# if @REPLACE_MBRLEN@
f4c79b3c
LC
217# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
218# undef mbrlen
219# define mbrlen rpl_mbrlen
220# endif
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));
223# else
224# if !@HAVE_MBRLEN@
225_GL_FUNCDECL_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
226# endif
227_GL_CXXALIAS_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
4a462e35 228# endif
f4c79b3c 229_GL_CXXALIASWARN (mbrlen);
4a462e35
NJ
230#elif defined GNULIB_POSIXCHECK
231# undef mbrlen
61cd9dc9
LC
232# if HAVE_RAW_DECL_MBRLEN
233_GL_WARN_ON_USE (mbrlen, "mbrlen is unportable - "
234 "use gnulib module mbrlen for portability");
235# endif
4a462e35
NJ
236#endif
237
238
239/* Convert a string to a wide string. */
240#if @GNULIB_MBSRTOWCS@
241# if @REPLACE_MBSRTOWCS@
f4c79b3c
LC
242# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
243# undef mbsrtowcs
244# define mbsrtowcs rpl_mbsrtowcs
245# endif
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,
251 mbstate_t *ps));
252# else
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)));
257# endif
258_GL_CXXALIAS_SYS (mbsrtowcs, size_t,
259 (wchar_t *dest, const char **srcp, size_t len,
260 mbstate_t *ps));
4a462e35 261# endif
f4c79b3c 262_GL_CXXALIASWARN (mbsrtowcs);
4a462e35
NJ
263#elif defined GNULIB_POSIXCHECK
264# undef mbsrtowcs
61cd9dc9
LC
265# if HAVE_RAW_DECL_MBSRTOWCS
266_GL_WARN_ON_USE (mbsrtowcs, "mbsrtowcs is unportable - "
267 "use gnulib module mbsrtowcs for portability");
268# endif
4a462e35
NJ
269#endif
270
271
272/* Convert a string to a wide string. */
273#if @GNULIB_MBSNRTOWCS@
274# if @REPLACE_MBSNRTOWCS@
f4c79b3c
LC
275# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
276# undef mbsnrtowcs
277# define mbsnrtowcs rpl_mbsnrtowcs
278# endif
279_GL_FUNCDECL_RPL (mbsnrtowcs, size_t,
280 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
281 mbstate_t *ps)
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,
285 mbstate_t *ps));
286# else
287# if !@HAVE_MBSNRTOWCS@
288_GL_FUNCDECL_SYS (mbsnrtowcs, size_t,
289 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
290 mbstate_t *ps)
291 _GL_ARG_NONNULL ((2)));
292# endif
293_GL_CXXALIAS_SYS (mbsnrtowcs, size_t,
294 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
295 mbstate_t *ps));
4a462e35 296# endif
f4c79b3c 297_GL_CXXALIASWARN (mbsnrtowcs);
4a462e35
NJ
298#elif defined GNULIB_POSIXCHECK
299# undef mbsnrtowcs
61cd9dc9
LC
300# if HAVE_RAW_DECL_MBSNRTOWCS
301_GL_WARN_ON_USE (mbsnrtowcs, "mbsnrtowcs is unportable - "
302 "use gnulib module mbsnrtowcs for portability");
303# endif
4a462e35
NJ
304#endif
305
306
307/* Convert a wide character to a multibyte character. */
308#if @GNULIB_WCRTOMB@
309# if @REPLACE_WCRTOMB@
f4c79b3c
LC
310# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
311# undef wcrtomb
312# define wcrtomb rpl_wcrtomb
313# endif
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));
316# else
317# if !@HAVE_WCRTOMB@
318_GL_FUNCDECL_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
319# endif
320_GL_CXXALIAS_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
4a462e35 321# endif
f4c79b3c 322_GL_CXXALIASWARN (wcrtomb);
4a462e35
NJ
323#elif defined GNULIB_POSIXCHECK
324# undef wcrtomb
61cd9dc9
LC
325# if HAVE_RAW_DECL_WCRTOMB
326_GL_WARN_ON_USE (wcrtomb, "wcrtomb is unportable - "
327 "use gnulib module wcrtomb for portability");
328# endif
4a462e35
NJ
329#endif
330
331
332/* Convert a wide string to a string. */
333#if @GNULIB_WCSRTOMBS@
334# if @REPLACE_WCSRTOMBS@
f4c79b3c
LC
335# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
336# undef wcsrtombs
337# define wcsrtombs rpl_wcsrtombs
338# endif
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,
344 mbstate_t *ps));
345# else
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)));
350# endif
351_GL_CXXALIAS_SYS (wcsrtombs, size_t,
352 (char *dest, const wchar_t **srcp, size_t len,
353 mbstate_t *ps));
4a462e35 354# endif
f4c79b3c 355_GL_CXXALIASWARN (wcsrtombs);
4a462e35
NJ
356#elif defined GNULIB_POSIXCHECK
357# undef wcsrtombs
61cd9dc9
LC
358# if HAVE_RAW_DECL_WCSRTOMBS
359_GL_WARN_ON_USE (wcsrtombs, "wcsrtombs is unportable - "
360 "use gnulib module wcsrtombs for portability");
361# endif
4a462e35
NJ
362#endif
363
364
365/* Convert a wide string to a string. */
366#if @GNULIB_WCSNRTOMBS@
f240aacb 367# if @REPLACE_WCSNRTOMBS@
f4c79b3c
LC
368# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
369# undef wcsnrtombs
370# define wcsnrtombs rpl_wcsnrtombs
371# endif
372_GL_FUNCDECL_RPL (wcsnrtombs, size_t,
373 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
374 mbstate_t *ps)
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,
378 mbstate_t *ps));
379# else
380# if !@HAVE_WCSNRTOMBS@
381_GL_FUNCDECL_SYS (wcsnrtombs, size_t,
382 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
383 mbstate_t *ps)
384 _GL_ARG_NONNULL ((2)));
385# endif
386_GL_CXXALIAS_SYS (wcsnrtombs, size_t,
387 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
388 mbstate_t *ps));
4a462e35 389# endif
f4c79b3c 390_GL_CXXALIASWARN (wcsnrtombs);
4a462e35
NJ
391#elif defined GNULIB_POSIXCHECK
392# undef wcsnrtombs
61cd9dc9
LC
393# if HAVE_RAW_DECL_WCSNRTOMBS
394_GL_WARN_ON_USE (wcsnrtombs, "wcsnrtombs is unportable - "
395 "use gnulib module wcsnrtombs for portability");
396# endif
aa7a939c
LC
397#endif
398
399
e65fc94b
LC
400/* Return the number of screen columns needed for WC. */
401#if @GNULIB_WCWIDTH@
402# if @REPLACE_WCWIDTH@
f4c79b3c
LC
403# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
404# undef wcwidth
405# define wcwidth rpl_wcwidth
406# endif
407_GL_FUNCDECL_RPL (wcwidth, int, (wchar_t));
408_GL_CXXALIAS_RPL (wcwidth, int, (wchar_t));
e65fc94b 409# else
a927b6c1 410# if !@HAVE_DECL_WCWIDTH@
e65fc94b 411/* wcwidth exists but is not declared. */
f4c79b3c 412_GL_FUNCDECL_SYS (wcwidth, int, (wchar_t));
e65fc94b 413# endif
f4c79b3c 414_GL_CXXALIAS_SYS (wcwidth, int, (wchar_t));
e65fc94b 415# endif
f4c79b3c 416_GL_CXXALIASWARN (wcwidth);
e65fc94b
LC
417#elif defined GNULIB_POSIXCHECK
418# undef wcwidth
61cd9dc9
LC
419# if HAVE_RAW_DECL_WCWIDTH
420_GL_WARN_ON_USE (wcwidth, "wcwidth is unportable - "
421 "use gnulib module wcwidth for portability");
422# endif
e65fc94b
LC
423#endif
424
425
e65fc94b
LC
426#endif /* _GL_WCHAR_H */
427#endif /* _GL_WCHAR_H */
428#endif