wchar.in.h 13 KB

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