wchar.in.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
  2. Copyright (C) 2007-2009 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  14. /* Written by Eric Blake. */
  15. /*
  16. * ISO C 99 <wchar.h> for platforms that have issues.
  17. * <http://www.opengroup.org/susv3xbd/wchar.h.html>
  18. *
  19. * For now, this just ensures proper prerequisite inclusion order and
  20. * the declaration of wcwidth().
  21. */
  22. #if __GNUC__ >= 3
  23. @PRAGMA_SYSTEM_HEADER@
  24. #endif
  25. #if defined __need_mbstate_t || (defined __hpux && ((defined _INTTYPES_INCLUDED && !defined strtoimax) || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H))
  26. /* Special invocation convention:
  27. - Inside uClibc header files.
  28. - On HP-UX 11.00 we have a sequence of nested includes
  29. <wchar.h> -> <stdlib.h> -> <stdint.h>, and the latter includes <wchar.h>,
  30. once indirectly <stdint.h> -> <sys/types.h> -> <inttypes.h> -> <wchar.h>
  31. and once directly. In both situations 'wint_t' is not yet defined,
  32. therefore we cannot provide the function overrides; instead include only
  33. the system's <wchar.h>. */
  34. #@INCLUDE_NEXT@ @NEXT_WCHAR_H@
  35. #else
  36. /* Normal invocation convention. */
  37. #ifndef _GL_WCHAR_H
  38. #define _GL_WCHAR_H
  39. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  40. <wchar.h>.
  41. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  42. included before <wchar.h>. */
  43. #include <stddef.h>
  44. #include <stdio.h>
  45. #include <time.h>
  46. /* Include the original <wchar.h> if it exists.
  47. Some builds of uClibc lack it. */
  48. /* The include_next requires a split double-inclusion guard. */
  49. #if @HAVE_WCHAR_H@
  50. # @INCLUDE_NEXT@ @NEXT_WCHAR_H@
  51. #endif
  52. /* The definition of GL_LINK_WARNING is copied here. */
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. /* Define wint_t. (Also done in wctype.in.h.) */
  57. #if !@HAVE_WINT_T@ && !defined wint_t
  58. # define wint_t int
  59. # ifndef WEOF
  60. # define WEOF -1
  61. # endif
  62. #endif
  63. /* Override mbstate_t if it is too small.
  64. On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
  65. implementing mbrtowc for encodings like UTF-8. */
  66. #if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
  67. typedef int rpl_mbstate_t;
  68. # undef mbstate_t
  69. # define mbstate_t rpl_mbstate_t
  70. # define GNULIB_defined_mbstate_t 1
  71. #endif
  72. /* Convert a single-byte character to a wide character. */
  73. #if @GNULIB_BTOWC@
  74. # if @REPLACE_BTOWC@
  75. # undef btowc
  76. # define btowc rpl_btowc
  77. # endif
  78. # if !@HAVE_BTOWC@ || @REPLACE_BTOWC@
  79. extern wint_t btowc (int c);
  80. # endif
  81. #elif defined GNULIB_POSIXCHECK
  82. # undef btowc
  83. # define btowc(c) \
  84. (GL_LINK_WARNING ("btowc is unportable - " \
  85. "use gnulib module btowc for portability"), \
  86. btowc (c))
  87. #endif
  88. /* Convert a wide character to a single-byte character. */
  89. #if @GNULIB_WCTOB@
  90. # if @REPLACE_WCTOB@
  91. # undef wctob
  92. # define wctob rpl_wctob
  93. # endif
  94. # if (!defined wctob && !@HAVE_DECL_WCTOB@) || @REPLACE_WCTOB@
  95. /* wctob is provided by gnulib, or wctob exists but is not declared. */
  96. extern int wctob (wint_t wc);
  97. # endif
  98. #elif defined GNULIB_POSIXCHECK
  99. # undef wctob
  100. # define wctob(w) \
  101. (GL_LINK_WARNING ("wctob is unportable - " \
  102. "use gnulib module wctob for portability"), \
  103. wctob (w))
  104. #endif
  105. /* Test whether *PS is in the initial state. */
  106. #if @GNULIB_MBSINIT@
  107. # if @REPLACE_MBSINIT@
  108. # undef mbsinit
  109. # define mbsinit rpl_mbsinit
  110. # endif
  111. # if !@HAVE_MBSINIT@ || @REPLACE_MBSINIT@
  112. extern int mbsinit (const mbstate_t *ps);
  113. # endif
  114. #elif defined GNULIB_POSIXCHECK
  115. # undef mbsinit
  116. # define mbsinit(p) \
  117. (GL_LINK_WARNING ("mbsinit is unportable - " \
  118. "use gnulib module mbsinit for portability"), \
  119. mbsinit (p))
  120. #endif
  121. /* Convert a multibyte character to a wide character. */
  122. #if @GNULIB_MBRTOWC@
  123. # if @REPLACE_MBRTOWC@
  124. # undef mbrtowc
  125. # define mbrtowc rpl_mbrtowc
  126. # endif
  127. # if !@HAVE_MBRTOWC@ || @REPLACE_MBRTOWC@
  128. extern size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
  129. # endif
  130. #elif defined GNULIB_POSIXCHECK
  131. # undef mbrtowc
  132. # define mbrtowc(w,s,n,p) \
  133. (GL_LINK_WARNING ("mbrtowc is unportable - " \
  134. "use gnulib module mbrtowc for portability"), \
  135. mbrtowc (w, s, n, p))
  136. #endif
  137. /* Recognize a multibyte character. */
  138. #if @GNULIB_MBRLEN@
  139. # if @REPLACE_MBRLEN@
  140. # undef mbrlen
  141. # define mbrlen rpl_mbrlen
  142. # endif
  143. # if !@HAVE_MBRLEN@ || @REPLACE_MBRLEN@
  144. extern size_t mbrlen (const char *s, size_t n, mbstate_t *ps);
  145. # endif
  146. #elif defined GNULIB_POSIXCHECK
  147. # undef mbrlen
  148. # define mbrlen(s,n,p) \
  149. (GL_LINK_WARNING ("mbrlen is unportable - " \
  150. "use gnulib module mbrlen for portability"), \
  151. mbrlen (s, n, p))
  152. #endif
  153. /* Convert a string to a wide string. */
  154. #if @GNULIB_MBSRTOWCS@
  155. # if @REPLACE_MBSRTOWCS@
  156. # undef mbsrtowcs
  157. # define mbsrtowcs rpl_mbsrtowcs
  158. # endif
  159. # if !@HAVE_MBSRTOWCS@ || @REPLACE_MBSRTOWCS@
  160. extern size_t mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps);
  161. # endif
  162. #elif defined GNULIB_POSIXCHECK
  163. # undef mbsrtowcs
  164. # define mbsrtowcs(d,s,l,p) \
  165. (GL_LINK_WARNING ("mbsrtowcs is unportable - " \
  166. "use gnulib module mbsrtowcs for portability"), \
  167. mbsrtowcs (d, s, l, p))
  168. #endif
  169. /* Convert a string to a wide string. */
  170. #if @GNULIB_MBSNRTOWCS@
  171. # if @REPLACE_MBSNRTOWCS@
  172. # undef mbsnrtowcs
  173. # define mbsnrtowcs rpl_mbsnrtowcs
  174. # endif
  175. # if !@HAVE_MBSNRTOWCS@ || @REPLACE_MBSNRTOWCS@
  176. extern size_t mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps);
  177. # endif
  178. #elif defined GNULIB_POSIXCHECK
  179. # undef mbsnrtowcs
  180. # define mbsnrtowcs(d,s,n,l,p) \
  181. (GL_LINK_WARNING ("mbsnrtowcs is unportable - " \
  182. "use gnulib module mbsnrtowcs for portability"), \
  183. mbsnrtowcs (d, s, n, l, p))
  184. #endif
  185. /* Convert a wide character to a multibyte character. */
  186. #if @GNULIB_WCRTOMB@
  187. # if @REPLACE_WCRTOMB@
  188. # undef wcrtomb
  189. # define wcrtomb rpl_wcrtomb
  190. # endif
  191. # if !@HAVE_WCRTOMB@ || @REPLACE_WCRTOMB@
  192. extern size_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps);
  193. # endif
  194. #elif defined GNULIB_POSIXCHECK
  195. # undef wcrtomb
  196. # define wcrtomb(s,w,p) \
  197. (GL_LINK_WARNING ("wcrtomb is unportable - " \
  198. "use gnulib module wcrtomb for portability"), \
  199. wcrtomb (s, w, p))
  200. #endif
  201. /* Convert a wide string to a string. */
  202. #if @GNULIB_WCSRTOMBS@
  203. # if @REPLACE_WCSRTOMBS@
  204. # undef wcsrtombs
  205. # define wcsrtombs rpl_wcsrtombs
  206. # endif
  207. # if !@HAVE_WCSRTOMBS@ || @REPLACE_WCSRTOMBS@
  208. extern size_t wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps);
  209. # endif
  210. #elif defined GNULIB_POSIXCHECK
  211. # undef wcsrtombs
  212. # define wcsrtombs(d,s,l,p) \
  213. (GL_LINK_WARNING ("wcsrtombs is unportable - " \
  214. "use gnulib module wcsrtombs for portability"), \
  215. wcsrtombs (d, s, l, p))
  216. #endif
  217. /* Convert a wide string to a string. */
  218. #if @GNULIB_WCSNRTOMBS@
  219. # if !@HAVE_WCSNRTOMBS@
  220. extern size_t wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps);
  221. # endif
  222. #elif defined GNULIB_POSIXCHECK
  223. # undef wcsnrtombs
  224. # define wcsnrtombs(d,s,n,l,p) \
  225. (GL_LINK_WARNING ("wcsnrtombs is unportable - " \
  226. "use gnulib module wcsnrtombs for portability"), \
  227. wcsnrtombs (d, s, n, l, p))
  228. #endif
  229. /* Return the number of screen columns needed for WC. */
  230. #if @GNULIB_WCWIDTH@
  231. # if @REPLACE_WCWIDTH@
  232. # undef wcwidth
  233. # define wcwidth rpl_wcwidth
  234. extern int wcwidth (wchar_t);
  235. # else
  236. # if !defined wcwidth && !@HAVE_DECL_WCWIDTH@
  237. /* wcwidth exists but is not declared. */
  238. extern int wcwidth (int /* actually wchar_t */);
  239. # endif
  240. # endif
  241. #elif defined GNULIB_POSIXCHECK
  242. # undef wcwidth
  243. # define wcwidth(w) \
  244. (GL_LINK_WARNING ("wcwidth is unportable - " \
  245. "use gnulib module wcwidth for portability"), \
  246. wcwidth (w))
  247. #endif
  248. #ifdef __cplusplus
  249. }
  250. #endif
  251. #endif /* _GL_WCHAR_H */
  252. #endif