wchar.in.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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)) || defined _GL_ALREADY_INCLUDING_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. - On IRIX 6.5, similarly, we have an include <wchar.h> -> <wctype.h>, and
  35. the latter includes <wchar.h>. But here, we have no way to detect whether
  36. <wctype.h> is completely included or is still being included. */
  37. #@INCLUDE_NEXT@ @NEXT_WCHAR_H@
  38. #else
  39. /* Normal invocation convention. */
  40. #ifndef _GL_WCHAR_H
  41. #define _GL_ALREADY_INCLUDING_WCHAR_H
  42. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  43. <wchar.h>.
  44. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  45. included before <wchar.h>. */
  46. #include <stddef.h>
  47. #include <stdio.h>
  48. #include <time.h>
  49. /* Include the original <wchar.h> if it exists.
  50. Some builds of uClibc lack it. */
  51. /* The include_next requires a split double-inclusion guard. */
  52. #if @HAVE_WCHAR_H@
  53. # @INCLUDE_NEXT@ @NEXT_WCHAR_H@
  54. #endif
  55. #undef _GL_ALREADY_INCLUDING_WCHAR_H
  56. #ifndef _GL_WCHAR_H
  57. #define _GL_WCHAR_H
  58. /* The definition of GL_LINK_WARNING is copied here. */
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62. /* Define wint_t. (Also done in wctype.in.h.) */
  63. #if !@HAVE_WINT_T@ && !defined wint_t
  64. # define wint_t int
  65. # ifndef WEOF
  66. # define WEOF -1
  67. # endif
  68. #endif
  69. /* Override mbstate_t if it is too small.
  70. On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
  71. implementing mbrtowc for encodings like UTF-8. */
  72. #if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
  73. typedef int rpl_mbstate_t;
  74. # undef mbstate_t
  75. # define mbstate_t rpl_mbstate_t
  76. # define GNULIB_defined_mbstate_t 1
  77. #endif
  78. /* Convert a single-byte character to a wide character. */
  79. #if @GNULIB_BTOWC@
  80. # if @REPLACE_BTOWC@
  81. # undef btowc
  82. # define btowc rpl_btowc
  83. # endif
  84. # if !@HAVE_BTOWC@ || @REPLACE_BTOWC@
  85. extern wint_t btowc (int c);
  86. # endif
  87. #elif defined GNULIB_POSIXCHECK
  88. # undef btowc
  89. # define btowc(c) \
  90. (GL_LINK_WARNING ("btowc is unportable - " \
  91. "use gnulib module btowc for portability"), \
  92. btowc (c))
  93. #endif
  94. /* Convert a wide character to a single-byte character. */
  95. #if @GNULIB_WCTOB@
  96. # if @REPLACE_WCTOB@
  97. # undef wctob
  98. # define wctob rpl_wctob
  99. # endif
  100. # if (!defined wctob && !@HAVE_DECL_WCTOB@) || @REPLACE_WCTOB@
  101. /* wctob is provided by gnulib, or wctob exists but is not declared. */
  102. extern int wctob (wint_t wc);
  103. # endif
  104. #elif defined GNULIB_POSIXCHECK
  105. # undef wctob
  106. # define wctob(w) \
  107. (GL_LINK_WARNING ("wctob is unportable - " \
  108. "use gnulib module wctob for portability"), \
  109. wctob (w))
  110. #endif
  111. /* Test whether *PS is in the initial state. */
  112. #if @GNULIB_MBSINIT@
  113. # if @REPLACE_MBSINIT@
  114. # undef mbsinit
  115. # define mbsinit rpl_mbsinit
  116. # endif
  117. # if !@HAVE_MBSINIT@ || @REPLACE_MBSINIT@
  118. extern int mbsinit (const mbstate_t *ps);
  119. # endif
  120. #elif defined GNULIB_POSIXCHECK
  121. # undef mbsinit
  122. # define mbsinit(p) \
  123. (GL_LINK_WARNING ("mbsinit is unportable - " \
  124. "use gnulib module mbsinit for portability"), \
  125. mbsinit (p))
  126. #endif
  127. /* Convert a multibyte character to a wide character. */
  128. #if @GNULIB_MBRTOWC@
  129. # if @REPLACE_MBRTOWC@
  130. # undef mbrtowc
  131. # define mbrtowc rpl_mbrtowc
  132. # endif
  133. # if !@HAVE_MBRTOWC@ || @REPLACE_MBRTOWC@
  134. extern size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
  135. # endif
  136. #elif defined GNULIB_POSIXCHECK
  137. # undef mbrtowc
  138. # define mbrtowc(w,s,n,p) \
  139. (GL_LINK_WARNING ("mbrtowc is unportable - " \
  140. "use gnulib module mbrtowc for portability"), \
  141. mbrtowc (w, s, n, p))
  142. #endif
  143. /* Recognize a multibyte character. */
  144. #if @GNULIB_MBRLEN@
  145. # if @REPLACE_MBRLEN@
  146. # undef mbrlen
  147. # define mbrlen rpl_mbrlen
  148. # endif
  149. # if !@HAVE_MBRLEN@ || @REPLACE_MBRLEN@
  150. extern size_t mbrlen (const char *s, size_t n, mbstate_t *ps);
  151. # endif
  152. #elif defined GNULIB_POSIXCHECK
  153. # undef mbrlen
  154. # define mbrlen(s,n,p) \
  155. (GL_LINK_WARNING ("mbrlen is unportable - " \
  156. "use gnulib module mbrlen for portability"), \
  157. mbrlen (s, n, p))
  158. #endif
  159. /* Convert a string to a wide string. */
  160. #if @GNULIB_MBSRTOWCS@
  161. # if @REPLACE_MBSRTOWCS@
  162. # undef mbsrtowcs
  163. # define mbsrtowcs rpl_mbsrtowcs
  164. # endif
  165. # if !@HAVE_MBSRTOWCS@ || @REPLACE_MBSRTOWCS@
  166. extern size_t mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps);
  167. # endif
  168. #elif defined GNULIB_POSIXCHECK
  169. # undef mbsrtowcs
  170. # define mbsrtowcs(d,s,l,p) \
  171. (GL_LINK_WARNING ("mbsrtowcs is unportable - " \
  172. "use gnulib module mbsrtowcs for portability"), \
  173. mbsrtowcs (d, s, l, p))
  174. #endif
  175. /* Convert a string to a wide string. */
  176. #if @GNULIB_MBSNRTOWCS@
  177. # if @REPLACE_MBSNRTOWCS@
  178. # undef mbsnrtowcs
  179. # define mbsnrtowcs rpl_mbsnrtowcs
  180. # endif
  181. # if !@HAVE_MBSNRTOWCS@ || @REPLACE_MBSNRTOWCS@
  182. extern size_t mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps);
  183. # endif
  184. #elif defined GNULIB_POSIXCHECK
  185. # undef mbsnrtowcs
  186. # define mbsnrtowcs(d,s,n,l,p) \
  187. (GL_LINK_WARNING ("mbsnrtowcs is unportable - " \
  188. "use gnulib module mbsnrtowcs for portability"), \
  189. mbsnrtowcs (d, s, n, l, p))
  190. #endif
  191. /* Convert a wide character to a multibyte character. */
  192. #if @GNULIB_WCRTOMB@
  193. # if @REPLACE_WCRTOMB@
  194. # undef wcrtomb
  195. # define wcrtomb rpl_wcrtomb
  196. # endif
  197. # if !@HAVE_WCRTOMB@ || @REPLACE_WCRTOMB@
  198. extern size_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps);
  199. # endif
  200. #elif defined GNULIB_POSIXCHECK
  201. # undef wcrtomb
  202. # define wcrtomb(s,w,p) \
  203. (GL_LINK_WARNING ("wcrtomb is unportable - " \
  204. "use gnulib module wcrtomb for portability"), \
  205. wcrtomb (s, w, p))
  206. #endif
  207. /* Convert a wide string to a string. */
  208. #if @GNULIB_WCSRTOMBS@
  209. # if @REPLACE_WCSRTOMBS@
  210. # undef wcsrtombs
  211. # define wcsrtombs rpl_wcsrtombs
  212. # endif
  213. # if !@HAVE_WCSRTOMBS@ || @REPLACE_WCSRTOMBS@
  214. extern size_t wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps);
  215. # endif
  216. #elif defined GNULIB_POSIXCHECK
  217. # undef wcsrtombs
  218. # define wcsrtombs(d,s,l,p) \
  219. (GL_LINK_WARNING ("wcsrtombs is unportable - " \
  220. "use gnulib module wcsrtombs for portability"), \
  221. wcsrtombs (d, s, l, p))
  222. #endif
  223. /* Convert a wide string to a string. */
  224. #if @GNULIB_WCSNRTOMBS@
  225. # if @REPLACE_WCSNRTOMBS@
  226. # undef wcsnrtombs
  227. # define wcsnrtombs rpl_wcsnrtombs
  228. # endif
  229. # if !@HAVE_WCSNRTOMBS@ || @REPLACE_WCSNRTOMBS@
  230. extern size_t wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps);
  231. # endif
  232. #elif defined GNULIB_POSIXCHECK
  233. # undef wcsnrtombs
  234. # define wcsnrtombs(d,s,n,l,p) \
  235. (GL_LINK_WARNING ("wcsnrtombs is unportable - " \
  236. "use gnulib module wcsnrtombs for portability"), \
  237. wcsnrtombs (d, s, n, l, p))
  238. #endif
  239. /* Return the number of screen columns needed for WC. */
  240. #if @GNULIB_WCWIDTH@
  241. # if @REPLACE_WCWIDTH@
  242. # undef wcwidth
  243. # define wcwidth rpl_wcwidth
  244. extern int wcwidth (wchar_t);
  245. # else
  246. # if !defined wcwidth && !@HAVE_DECL_WCWIDTH@
  247. /* wcwidth exists but is not declared. */
  248. extern int wcwidth (int /* actually wchar_t */);
  249. # endif
  250. # endif
  251. #elif defined GNULIB_POSIXCHECK
  252. # undef wcwidth
  253. # define wcwidth(w) \
  254. (GL_LINK_WARNING ("wcwidth is unportable - " \
  255. "use gnulib module wcwidth for portability"), \
  256. wcwidth (w))
  257. #endif
  258. #ifdef __cplusplus
  259. }
  260. #endif
  261. #endif /* _GL_WCHAR_H */
  262. #endif /* _GL_WCHAR_H */
  263. #endif