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