434
|
1 /* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
|
|
2
|
|
3 Copyright (C) 2007-2010 Free Software Foundation, Inc.
|
|
4
|
|
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)
|
|
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 General Public License for more details.
|
|
14
|
|
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. */
|
|
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
|
|
29 #if __GNUC__ >= 3
|
|
30 @PRAGMA_SYSTEM_HEADER@
|
|
31 #endif
|
|
32
|
|
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. */
|
|
45
|
|
46 #@INCLUDE_NEXT@ @NEXT_WCHAR_H@
|
|
47
|
|
48 #else
|
|
49 /* Normal invocation convention. */
|
|
50
|
|
51 #ifndef _GL_WCHAR_H
|
|
52
|
|
53 #define _GL_ALREADY_INCLUDING_WCHAR_H
|
|
54
|
|
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
|
|
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
|
|
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
|
|
73 #undef _GL_ALREADY_INCLUDING_WCHAR_H
|
|
74
|
|
75 #ifndef _GL_WCHAR_H
|
|
76 #define _GL_WCHAR_H
|
|
77
|
|
78 /* The definition of GL_LINK_WARNING is copied here. */
|
|
79
|
|
80 /* The definition of _GL_ARG_NONNULL is copied here. */
|
|
81
|
|
82 #ifdef __cplusplus
|
|
83 extern "C" {
|
|
84 #endif
|
|
85
|
|
86
|
|
87 /* Define wint_t. (Also done in wctype.in.h.) */
|
|
88 #if !@HAVE_WINT_T@ && !defined wint_t
|
|
89 # define wint_t int
|
|
90 # ifndef WEOF
|
|
91 # define WEOF -1
|
|
92 # endif
|
|
93 #endif
|
|
94
|
|
95
|
|
96 /* Override mbstate_t if it is too small.
|
|
97 On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
|
|
98 implementing mbrtowc for encodings like UTF-8. */
|
|
99 #if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
|
|
100 typedef int rpl_mbstate_t;
|
|
101 # undef mbstate_t
|
|
102 # define mbstate_t rpl_mbstate_t
|
|
103 # define GNULIB_defined_mbstate_t 1
|
|
104 #endif
|
|
105
|
|
106
|
|
107 /* Convert a single-byte character to a wide character. */
|
|
108 #if @GNULIB_BTOWC@
|
|
109 # if @REPLACE_BTOWC@
|
|
110 # undef btowc
|
|
111 # define btowc rpl_btowc
|
|
112 # endif
|
|
113 # if !@HAVE_BTOWC@ || @REPLACE_BTOWC@
|
|
114 extern wint_t btowc (int c);
|
|
115 # endif
|
|
116 #elif defined GNULIB_POSIXCHECK
|
|
117 # undef btowc
|
|
118 # define btowc(c) \
|
|
119 (GL_LINK_WARNING ("btowc is unportable - " \
|
|
120 "use gnulib module btowc for portability"), \
|
|
121 btowc (c))
|
|
122 #endif
|
|
123
|
|
124
|
|
125 /* Convert a wide character to a single-byte character. */
|
|
126 #if @GNULIB_WCTOB@
|
|
127 # if @REPLACE_WCTOB@
|
|
128 # undef wctob
|
|
129 # define wctob rpl_wctob
|
|
130 # endif
|
|
131 # if (!defined wctob && !@HAVE_DECL_WCTOB@) || @REPLACE_WCTOB@
|
|
132 /* wctob is provided by gnulib, or wctob exists but is not declared. */
|
|
133 extern int wctob (wint_t wc);
|
|
134 # endif
|
|
135 #elif defined GNULIB_POSIXCHECK
|
|
136 # undef wctob
|
|
137 # define wctob(w) \
|
|
138 (GL_LINK_WARNING ("wctob is unportable - " \
|
|
139 "use gnulib module wctob for portability"), \
|
|
140 wctob (w))
|
|
141 #endif
|
|
142
|
|
143
|
|
144 /* Test whether *PS is in the initial state. */
|
|
145 #if @GNULIB_MBSINIT@
|
|
146 # if @REPLACE_MBSINIT@
|
|
147 # undef mbsinit
|
|
148 # define mbsinit rpl_mbsinit
|
|
149 # endif
|
|
150 # if !@HAVE_MBSINIT@ || @REPLACE_MBSINIT@
|
|
151 extern int mbsinit (const mbstate_t *ps);
|
|
152 # endif
|
|
153 #elif defined GNULIB_POSIXCHECK
|
|
154 # undef mbsinit
|
|
155 # define mbsinit(p) \
|
|
156 (GL_LINK_WARNING ("mbsinit is unportable - " \
|
|
157 "use gnulib module mbsinit for portability"), \
|
|
158 mbsinit (p))
|
|
159 #endif
|
|
160
|
|
161
|
|
162 /* Convert a multibyte character to a wide character. */
|
|
163 #if @GNULIB_MBRTOWC@
|
|
164 # if @REPLACE_MBRTOWC@
|
|
165 # undef mbrtowc
|
|
166 # define mbrtowc rpl_mbrtowc
|
|
167 # endif
|
|
168 # if !@HAVE_MBRTOWC@ || @REPLACE_MBRTOWC@
|
|
169 extern size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
|
|
170 # endif
|
|
171 #elif defined GNULIB_POSIXCHECK
|
|
172 # undef mbrtowc
|
|
173 # define mbrtowc(w,s,n,p) \
|
|
174 (GL_LINK_WARNING ("mbrtowc is unportable - " \
|
|
175 "use gnulib module mbrtowc for portability"), \
|
|
176 mbrtowc (w, s, n, p))
|
|
177 #endif
|
|
178
|
|
179
|
|
180 /* Recognize a multibyte character. */
|
|
181 #if @GNULIB_MBRLEN@
|
|
182 # if @REPLACE_MBRLEN@
|
|
183 # undef mbrlen
|
|
184 # define mbrlen rpl_mbrlen
|
|
185 # endif
|
|
186 # if !@HAVE_MBRLEN@ || @REPLACE_MBRLEN@
|
|
187 extern size_t mbrlen (const char *s, size_t n, mbstate_t *ps);
|
|
188 # endif
|
|
189 #elif defined GNULIB_POSIXCHECK
|
|
190 # undef mbrlen
|
|
191 # define mbrlen(s,n,p) \
|
|
192 (GL_LINK_WARNING ("mbrlen is unportable - " \
|
|
193 "use gnulib module mbrlen for portability"), \
|
|
194 mbrlen (s, n, p))
|
|
195 #endif
|
|
196
|
|
197
|
|
198 /* Convert a string to a wide string. */
|
|
199 #if @GNULIB_MBSRTOWCS@
|
|
200 # if @REPLACE_MBSRTOWCS@
|
|
201 # undef mbsrtowcs
|
|
202 # define mbsrtowcs rpl_mbsrtowcs
|
|
203 # endif
|
|
204 # if !@HAVE_MBSRTOWCS@ || @REPLACE_MBSRTOWCS@
|
|
205 extern size_t mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps)
|
|
206 _GL_ARG_NONNULL ((2));
|
|
207 # endif
|
|
208 #elif defined GNULIB_POSIXCHECK
|
|
209 # undef mbsrtowcs
|
|
210 # define mbsrtowcs(d,s,l,p) \
|
|
211 (GL_LINK_WARNING ("mbsrtowcs is unportable - " \
|
|
212 "use gnulib module mbsrtowcs for portability"), \
|
|
213 mbsrtowcs (d, s, l, p))
|
|
214 #endif
|
|
215
|
|
216
|
|
217 /* Convert a string to a wide string. */
|
|
218 #if @GNULIB_MBSNRTOWCS@
|
|
219 # if @REPLACE_MBSNRTOWCS@
|
|
220 # undef mbsnrtowcs
|
|
221 # define mbsnrtowcs rpl_mbsnrtowcs
|
|
222 # endif
|
|
223 # if !@HAVE_MBSNRTOWCS@ || @REPLACE_MBSNRTOWCS@
|
|
224 extern size_t mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps)
|
|
225 _GL_ARG_NONNULL ((2));
|
|
226 # endif
|
|
227 #elif defined GNULIB_POSIXCHECK
|
|
228 # undef mbsnrtowcs
|
|
229 # define mbsnrtowcs(d,s,n,l,p) \
|
|
230 (GL_LINK_WARNING ("mbsnrtowcs is unportable - " \
|
|
231 "use gnulib module mbsnrtowcs for portability"), \
|
|
232 mbsnrtowcs (d, s, n, l, p))
|
|
233 #endif
|
|
234
|
|
235
|
|
236 /* Convert a wide character to a multibyte character. */
|
|
237 #if @GNULIB_WCRTOMB@
|
|
238 # if @REPLACE_WCRTOMB@
|
|
239 # undef wcrtomb
|
|
240 # define wcrtomb rpl_wcrtomb
|
|
241 # endif
|
|
242 # if !@HAVE_WCRTOMB@ || @REPLACE_WCRTOMB@
|
|
243 extern size_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps);
|
|
244 # endif
|
|
245 #elif defined GNULIB_POSIXCHECK
|
|
246 # undef wcrtomb
|
|
247 # define wcrtomb(s,w,p) \
|
|
248 (GL_LINK_WARNING ("wcrtomb is unportable - " \
|
|
249 "use gnulib module wcrtomb for portability"), \
|
|
250 wcrtomb (s, w, p))
|
|
251 #endif
|
|
252
|
|
253
|
|
254 /* Convert a wide string to a string. */
|
|
255 #if @GNULIB_WCSRTOMBS@
|
|
256 # if @REPLACE_WCSRTOMBS@
|
|
257 # undef wcsrtombs
|
|
258 # define wcsrtombs rpl_wcsrtombs
|
|
259 # endif
|
|
260 # if !@HAVE_WCSRTOMBS@ || @REPLACE_WCSRTOMBS@
|
|
261 extern size_t wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps)
|
|
262 _GL_ARG_NONNULL ((2));
|
|
263 # endif
|
|
264 #elif defined GNULIB_POSIXCHECK
|
|
265 # undef wcsrtombs
|
|
266 # define wcsrtombs(d,s,l,p) \
|
|
267 (GL_LINK_WARNING ("wcsrtombs is unportable - " \
|
|
268 "use gnulib module wcsrtombs for portability"), \
|
|
269 wcsrtombs (d, s, l, p))
|
|
270 #endif
|
|
271
|
|
272
|
|
273 /* Convert a wide string to a string. */
|
|
274 #if @GNULIB_WCSNRTOMBS@
|
|
275 # if @REPLACE_WCSNRTOMBS@
|
|
276 # undef wcsnrtombs
|
|
277 # define wcsnrtombs rpl_wcsnrtombs
|
|
278 # endif
|
|
279 # if !@HAVE_WCSNRTOMBS@ || @REPLACE_WCSNRTOMBS@
|
|
280 extern size_t wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps)
|
|
281 _GL_ARG_NONNULL ((2));
|
|
282 # endif
|
|
283 #elif defined GNULIB_POSIXCHECK
|
|
284 # undef wcsnrtombs
|
|
285 # define wcsnrtombs(d,s,n,l,p) \
|
|
286 (GL_LINK_WARNING ("wcsnrtombs is unportable - " \
|
|
287 "use gnulib module wcsnrtombs for portability"), \
|
|
288 wcsnrtombs (d, s, n, l, p))
|
|
289 #endif
|
|
290
|
|
291
|
|
292 /* Return the number of screen columns needed for WC. */
|
|
293 #if @GNULIB_WCWIDTH@
|
|
294 # if @REPLACE_WCWIDTH@
|
|
295 # undef wcwidth
|
|
296 # define wcwidth rpl_wcwidth
|
|
297 extern int wcwidth (wchar_t);
|
|
298 # else
|
|
299 # if !defined wcwidth && !@HAVE_DECL_WCWIDTH@
|
|
300 /* wcwidth exists but is not declared. */
|
|
301 extern int wcwidth (int /* actually wchar_t */);
|
|
302 # endif
|
|
303 # endif
|
|
304 #elif defined GNULIB_POSIXCHECK
|
|
305 # undef wcwidth
|
|
306 # define wcwidth(w) \
|
|
307 (GL_LINK_WARNING ("wcwidth is unportable - " \
|
|
308 "use gnulib module wcwidth for portability"), \
|
|
309 wcwidth (w))
|
|
310 #endif
|
|
311
|
|
312
|
|
313 #ifdef __cplusplus
|
|
314 }
|
|
315 #endif
|
|
316
|
|
317 #endif /* _GL_WCHAR_H */
|
|
318 #endif /* _GL_WCHAR_H */
|
|
319 #endif
|