Implementation for the R6RS (rnrs sorting) library.
[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
aa7a939c
LC
85/* Define wint_t. (Also done in wctype.in.h.) */
86#if !@HAVE_WINT_T@ && !defined wint_t
87# define wint_t int
4a462e35
NJ
88# ifndef WEOF
89# define WEOF -1
90# endif
91#endif
92
93
94/* Override mbstate_t if it is too small.
95 On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
96 implementing mbrtowc for encodings like UTF-8. */
97#if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
98typedef int rpl_mbstate_t;
99# undef mbstate_t
100# define mbstate_t rpl_mbstate_t
101# define GNULIB_defined_mbstate_t 1
102#endif
103
104
105/* Convert a single-byte character to a wide character. */
106#if @GNULIB_BTOWC@
107# if @REPLACE_BTOWC@
f4c79b3c
LC
108# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
109# undef btowc
110# define btowc rpl_btowc
111# endif
112_GL_FUNCDECL_RPL (btowc, wint_t, (int c));
113_GL_CXXALIAS_RPL (btowc, wint_t, (int c));
114# else
115# if !@HAVE_BTOWC@
116_GL_FUNCDECL_SYS (btowc, wint_t, (int c));
117# endif
118_GL_CXXALIAS_SYS (btowc, wint_t, (int c));
4a462e35 119# endif
f4c79b3c 120_GL_CXXALIASWARN (btowc);
4a462e35
NJ
121#elif defined GNULIB_POSIXCHECK
122# undef btowc
61cd9dc9
LC
123# if HAVE_RAW_DECL_BTOWC
124_GL_WARN_ON_USE (btowc, "btowc is unportable - "
125 "use gnulib module btowc for portability");
126# endif
4a462e35
NJ
127#endif
128
129
130/* Convert a wide character to a single-byte character. */
131#if @GNULIB_WCTOB@
132# if @REPLACE_WCTOB@
f4c79b3c
LC
133# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
134# undef wctob
135# define wctob rpl_wctob
136# endif
137_GL_FUNCDECL_RPL (wctob, int, (wint_t wc));
138_GL_CXXALIAS_RPL (wctob, int, (wint_t wc));
139# else
140# if !defined wctob && !@HAVE_DECL_WCTOB@
4a462e35 141/* wctob is provided by gnulib, or wctob exists but is not declared. */
f4c79b3c
LC
142_GL_FUNCDECL_SYS (wctob, int, (wint_t wc));
143# endif
144_GL_CXXALIAS_SYS (wctob, int, (wint_t wc));
4a462e35 145# endif
f4c79b3c 146_GL_CXXALIASWARN (wctob);
4a462e35
NJ
147#elif defined GNULIB_POSIXCHECK
148# undef wctob
61cd9dc9
LC
149# if HAVE_RAW_DECL_WCTOB
150_GL_WARN_ON_USE (wctob, "wctob is unportable - "
151 "use gnulib module wctob for portability");
152# endif
4a462e35
NJ
153#endif
154
155
156/* Test whether *PS is in the initial state. */
157#if @GNULIB_MBSINIT@
158# if @REPLACE_MBSINIT@
f4c79b3c
LC
159# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
160# undef mbsinit
161# define mbsinit rpl_mbsinit
162# endif
163_GL_FUNCDECL_RPL (mbsinit, int, (const mbstate_t *ps));
164_GL_CXXALIAS_RPL (mbsinit, int, (const mbstate_t *ps));
165# else
166# if !@HAVE_MBSINIT@
167_GL_FUNCDECL_SYS (mbsinit, int, (const mbstate_t *ps));
168# endif
169_GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps));
4a462e35 170# endif
f4c79b3c 171_GL_CXXALIASWARN (mbsinit);
4a462e35
NJ
172#elif defined GNULIB_POSIXCHECK
173# undef mbsinit
61cd9dc9
LC
174# if HAVE_RAW_DECL_MBSINIT
175_GL_WARN_ON_USE (mbsinit, "mbsinit is unportable - "
176 "use gnulib module mbsinit for portability");
177# endif
4a462e35
NJ
178#endif
179
180
181/* Convert a multibyte character to a wide character. */
182#if @GNULIB_MBRTOWC@
183# if @REPLACE_MBRTOWC@
f4c79b3c
LC
184# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
185# undef mbrtowc
186# define mbrtowc rpl_mbrtowc
187# endif
188_GL_FUNCDECL_RPL (mbrtowc, size_t,
189 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
190_GL_CXXALIAS_RPL (mbrtowc, size_t,
191 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
192# else
193# if !@HAVE_MBRTOWC@
194_GL_FUNCDECL_SYS (mbrtowc, size_t,
195 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
196# endif
197_GL_CXXALIAS_SYS (mbrtowc, size_t,
198 (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps));
4a462e35 199# endif
f4c79b3c 200_GL_CXXALIASWARN (mbrtowc);
4a462e35
NJ
201#elif defined GNULIB_POSIXCHECK
202# undef mbrtowc
61cd9dc9
LC
203# if HAVE_RAW_DECL_MBRTOWC
204_GL_WARN_ON_USE (mbrtowc, "mbrtowc is unportable - "
205 "use gnulib module mbrtowc for portability");
206# endif
4a462e35
NJ
207#endif
208
209
210/* Recognize a multibyte character. */
211#if @GNULIB_MBRLEN@
212# if @REPLACE_MBRLEN@
f4c79b3c
LC
213# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
214# undef mbrlen
215# define mbrlen rpl_mbrlen
216# endif
217_GL_FUNCDECL_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
218_GL_CXXALIAS_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
219# else
220# if !@HAVE_MBRLEN@
221_GL_FUNCDECL_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
222# endif
223_GL_CXXALIAS_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps));
4a462e35 224# endif
f4c79b3c 225_GL_CXXALIASWARN (mbrlen);
4a462e35
NJ
226#elif defined GNULIB_POSIXCHECK
227# undef mbrlen
61cd9dc9
LC
228# if HAVE_RAW_DECL_MBRLEN
229_GL_WARN_ON_USE (mbrlen, "mbrlen is unportable - "
230 "use gnulib module mbrlen for portability");
231# endif
4a462e35
NJ
232#endif
233
234
235/* Convert a string to a wide string. */
236#if @GNULIB_MBSRTOWCS@
237# if @REPLACE_MBSRTOWCS@
f4c79b3c
LC
238# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
239# undef mbsrtowcs
240# define mbsrtowcs rpl_mbsrtowcs
241# endif
242_GL_FUNCDECL_RPL (mbsrtowcs, size_t,
243 (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
244 _GL_ARG_NONNULL ((2)));
245_GL_CXXALIAS_RPL (mbsrtowcs, size_t,
246 (wchar_t *dest, const char **srcp, size_t len,
247 mbstate_t *ps));
248# else
249# if !@HAVE_MBSRTOWCS@
250_GL_FUNCDECL_SYS (mbsrtowcs, size_t,
251 (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
252 _GL_ARG_NONNULL ((2)));
253# endif
254_GL_CXXALIAS_SYS (mbsrtowcs, size_t,
255 (wchar_t *dest, const char **srcp, size_t len,
256 mbstate_t *ps));
4a462e35 257# endif
f4c79b3c 258_GL_CXXALIASWARN (mbsrtowcs);
4a462e35
NJ
259#elif defined GNULIB_POSIXCHECK
260# undef mbsrtowcs
61cd9dc9
LC
261# if HAVE_RAW_DECL_MBSRTOWCS
262_GL_WARN_ON_USE (mbsrtowcs, "mbsrtowcs is unportable - "
263 "use gnulib module mbsrtowcs for portability");
264# endif
4a462e35
NJ
265#endif
266
267
268/* Convert a string to a wide string. */
269#if @GNULIB_MBSNRTOWCS@
270# if @REPLACE_MBSNRTOWCS@
f4c79b3c
LC
271# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
272# undef mbsnrtowcs
273# define mbsnrtowcs rpl_mbsnrtowcs
274# endif
275_GL_FUNCDECL_RPL (mbsnrtowcs, size_t,
276 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
277 mbstate_t *ps)
278 _GL_ARG_NONNULL ((2)));
279_GL_CXXALIAS_RPL (mbsnrtowcs, size_t,
280 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
281 mbstate_t *ps));
282# else
283# if !@HAVE_MBSNRTOWCS@
284_GL_FUNCDECL_SYS (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# endif
289_GL_CXXALIAS_SYS (mbsnrtowcs, size_t,
290 (wchar_t *dest, const char **srcp, size_t srclen, size_t len,
291 mbstate_t *ps));
4a462e35 292# endif
f4c79b3c 293_GL_CXXALIASWARN (mbsnrtowcs);
4a462e35
NJ
294#elif defined GNULIB_POSIXCHECK
295# undef mbsnrtowcs
61cd9dc9
LC
296# if HAVE_RAW_DECL_MBSNRTOWCS
297_GL_WARN_ON_USE (mbsnrtowcs, "mbsnrtowcs is unportable - "
298 "use gnulib module mbsnrtowcs for portability");
299# endif
4a462e35
NJ
300#endif
301
302
303/* Convert a wide character to a multibyte character. */
304#if @GNULIB_WCRTOMB@
305# if @REPLACE_WCRTOMB@
f4c79b3c
LC
306# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
307# undef wcrtomb
308# define wcrtomb rpl_wcrtomb
309# endif
310_GL_FUNCDECL_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
311_GL_CXXALIAS_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
312# else
313# if !@HAVE_WCRTOMB@
314_GL_FUNCDECL_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
315# endif
316_GL_CXXALIAS_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps));
4a462e35 317# endif
f4c79b3c 318_GL_CXXALIASWARN (wcrtomb);
4a462e35
NJ
319#elif defined GNULIB_POSIXCHECK
320# undef wcrtomb
61cd9dc9
LC
321# if HAVE_RAW_DECL_WCRTOMB
322_GL_WARN_ON_USE (wcrtomb, "wcrtomb is unportable - "
323 "use gnulib module wcrtomb for portability");
324# endif
4a462e35
NJ
325#endif
326
327
328/* Convert a wide string to a string. */
329#if @GNULIB_WCSRTOMBS@
330# if @REPLACE_WCSRTOMBS@
f4c79b3c
LC
331# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
332# undef wcsrtombs
333# define wcsrtombs rpl_wcsrtombs
334# endif
335_GL_FUNCDECL_RPL (wcsrtombs, size_t,
336 (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
337 _GL_ARG_NONNULL ((2)));
338_GL_CXXALIAS_RPL (wcsrtombs, size_t,
339 (char *dest, const wchar_t **srcp, size_t len,
340 mbstate_t *ps));
341# else
342# if !@HAVE_WCSRTOMBS@
343_GL_FUNCDECL_SYS (wcsrtombs, size_t,
344 (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
345 _GL_ARG_NONNULL ((2)));
346# endif
347_GL_CXXALIAS_SYS (wcsrtombs, size_t,
348 (char *dest, const wchar_t **srcp, size_t len,
349 mbstate_t *ps));
4a462e35 350# endif
f4c79b3c 351_GL_CXXALIASWARN (wcsrtombs);
4a462e35
NJ
352#elif defined GNULIB_POSIXCHECK
353# undef wcsrtombs
61cd9dc9
LC
354# if HAVE_RAW_DECL_WCSRTOMBS
355_GL_WARN_ON_USE (wcsrtombs, "wcsrtombs is unportable - "
356 "use gnulib module wcsrtombs for portability");
357# endif
4a462e35
NJ
358#endif
359
360
361/* Convert a wide string to a string. */
362#if @GNULIB_WCSNRTOMBS@
f240aacb 363# if @REPLACE_WCSNRTOMBS@
f4c79b3c
LC
364# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
365# undef wcsnrtombs
366# define wcsnrtombs rpl_wcsnrtombs
367# endif
368_GL_FUNCDECL_RPL (wcsnrtombs, size_t,
369 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
370 mbstate_t *ps)
371 _GL_ARG_NONNULL ((2)));
372_GL_CXXALIAS_RPL (wcsnrtombs, size_t,
373 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
374 mbstate_t *ps));
375# else
376# if !@HAVE_WCSNRTOMBS@
377_GL_FUNCDECL_SYS (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# endif
382_GL_CXXALIAS_SYS (wcsnrtombs, size_t,
383 (char *dest, const wchar_t **srcp, size_t srclen, size_t len,
384 mbstate_t *ps));
4a462e35 385# endif
f4c79b3c 386_GL_CXXALIASWARN (wcsnrtombs);
4a462e35
NJ
387#elif defined GNULIB_POSIXCHECK
388# undef wcsnrtombs
61cd9dc9
LC
389# if HAVE_RAW_DECL_WCSNRTOMBS
390_GL_WARN_ON_USE (wcsnrtombs, "wcsnrtombs is unportable - "
391 "use gnulib module wcsnrtombs for portability");
392# endif
aa7a939c
LC
393#endif
394
395
e65fc94b
LC
396/* Return the number of screen columns needed for WC. */
397#if @GNULIB_WCWIDTH@
398# if @REPLACE_WCWIDTH@
f4c79b3c
LC
399# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
400# undef wcwidth
401# define wcwidth rpl_wcwidth
402# endif
403_GL_FUNCDECL_RPL (wcwidth, int, (wchar_t));
404_GL_CXXALIAS_RPL (wcwidth, int, (wchar_t));
e65fc94b
LC
405# else
406# if !defined wcwidth && !@HAVE_DECL_WCWIDTH@
407/* wcwidth exists but is not declared. */
f4c79b3c 408_GL_FUNCDECL_SYS (wcwidth, int, (wchar_t));
e65fc94b 409# endif
f4c79b3c 410_GL_CXXALIAS_SYS (wcwidth, int, (wchar_t));
e65fc94b 411# endif
f4c79b3c 412_GL_CXXALIASWARN (wcwidth);
e65fc94b
LC
413#elif defined GNULIB_POSIXCHECK
414# undef wcwidth
61cd9dc9
LC
415# if HAVE_RAW_DECL_WCWIDTH
416_GL_WARN_ON_USE (wcwidth, "wcwidth is unportable - "
417 "use gnulib module wcwidth for portability");
418# endif
e65fc94b
LC
419#endif
420
421
e65fc94b
LC
422#endif /* _GL_WCHAR_H */
423#endif /* _GL_WCHAR_H */
424#endif