mbrtowc.m4 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. # mbrtowc.m4 serial 25
  2. dnl Copyright (C) 2001-2002, 2004-2005, 2008-2013 Free Software Foundation,
  3. dnl Inc.
  4. dnl This file is free software; the Free Software Foundation
  5. dnl gives unlimited permission to copy and/or distribute it,
  6. dnl with or without modifications, as long as this notice is preserved.
  7. AC_DEFUN([gl_FUNC_MBRTOWC],
  8. [
  9. AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
  10. AC_REQUIRE([AC_TYPE_MBSTATE_T])
  11. gl_MBSTATE_T_BROKEN
  12. AC_CHECK_FUNCS_ONCE([mbrtowc])
  13. if test $ac_cv_func_mbrtowc = no; then
  14. HAVE_MBRTOWC=0
  15. AC_CHECK_DECLS([mbrtowc],,, [[
  16. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  17. <wchar.h>.
  18. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  19. included before <wchar.h>. */
  20. #include <stddef.h>
  21. #include <stdio.h>
  22. #include <time.h>
  23. #include <wchar.h>
  24. ]])
  25. if test $ac_cv_have_decl_mbrtowc = yes; then
  26. dnl On Minix 3.1.8, the system's <wchar.h> declares mbrtowc() although
  27. dnl it does not have the function. Avoid a collision with gnulib's
  28. dnl replacement.
  29. REPLACE_MBRTOWC=1
  30. fi
  31. else
  32. if test $REPLACE_MBSTATE_T = 1; then
  33. REPLACE_MBRTOWC=1
  34. else
  35. gl_MBRTOWC_NULL_ARG1
  36. gl_MBRTOWC_NULL_ARG2
  37. gl_MBRTOWC_RETVAL
  38. gl_MBRTOWC_NUL_RETVAL
  39. case "$gl_cv_func_mbrtowc_null_arg1" in
  40. *yes) ;;
  41. *) AC_DEFINE([MBRTOWC_NULL_ARG1_BUG], [1],
  42. [Define if the mbrtowc function has the NULL pwc argument bug.])
  43. REPLACE_MBRTOWC=1
  44. ;;
  45. esac
  46. case "$gl_cv_func_mbrtowc_null_arg2" in
  47. *yes) ;;
  48. *) AC_DEFINE([MBRTOWC_NULL_ARG2_BUG], [1],
  49. [Define if the mbrtowc function has the NULL string argument bug.])
  50. REPLACE_MBRTOWC=1
  51. ;;
  52. esac
  53. case "$gl_cv_func_mbrtowc_retval" in
  54. *yes) ;;
  55. *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1],
  56. [Define if the mbrtowc function returns a wrong return value.])
  57. REPLACE_MBRTOWC=1
  58. ;;
  59. esac
  60. case "$gl_cv_func_mbrtowc_nul_retval" in
  61. *yes) ;;
  62. *) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1],
  63. [Define if the mbrtowc function does not return 0 for a NUL character.])
  64. REPLACE_MBRTOWC=1
  65. ;;
  66. esac
  67. fi
  68. fi
  69. ])
  70. dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that
  71. dnl redefines the semantics of the given mbstate_t type.
  72. dnl Result is REPLACE_MBSTATE_T.
  73. dnl When this is set to 1, we replace both mbsinit() and mbrtowc(), in order to
  74. dnl avoid inconsistencies.
  75. AC_DEFUN([gl_MBSTATE_T_BROKEN],
  76. [
  77. AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
  78. AC_REQUIRE([AC_TYPE_MBSTATE_T])
  79. AC_CHECK_FUNCS_ONCE([mbsinit])
  80. AC_CHECK_FUNCS_ONCE([mbrtowc])
  81. if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then
  82. gl_MBRTOWC_INCOMPLETE_STATE
  83. gl_MBRTOWC_SANITYCHECK
  84. REPLACE_MBSTATE_T=0
  85. case "$gl_cv_func_mbrtowc_incomplete_state" in
  86. *yes) ;;
  87. *) REPLACE_MBSTATE_T=1 ;;
  88. esac
  89. case "$gl_cv_func_mbrtowc_sanitycheck" in
  90. *yes) ;;
  91. *) REPLACE_MBSTATE_T=1 ;;
  92. esac
  93. else
  94. REPLACE_MBSTATE_T=1
  95. fi
  96. ])
  97. dnl Test whether mbrtowc puts the state into non-initial state when parsing an
  98. dnl incomplete multibyte character.
  99. dnl Result is gl_cv_func_mbrtowc_incomplete_state.
  100. AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE],
  101. [
  102. AC_REQUIRE([AC_PROG_CC])
  103. AC_REQUIRE([gt_LOCALE_JA])
  104. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  105. AC_CACHE_CHECK([whether mbrtowc handles incomplete characters],
  106. [gl_cv_func_mbrtowc_incomplete_state],
  107. [
  108. dnl Initial guess, used when cross-compiling or when no suitable locale
  109. dnl is present.
  110. changequote(,)dnl
  111. case "$host_os" in
  112. # Guess no on AIX and OSF/1.
  113. aix* | osf*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;;
  114. # Guess yes otherwise.
  115. *) gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;;
  116. esac
  117. changequote([,])dnl
  118. if test $LOCALE_JA != none; then
  119. AC_RUN_IFELSE(
  120. [AC_LANG_SOURCE([[
  121. #include <locale.h>
  122. #include <string.h>
  123. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  124. <wchar.h>.
  125. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  126. included before <wchar.h>. */
  127. #include <stddef.h>
  128. #include <stdio.h>
  129. #include <time.h>
  130. #include <wchar.h>
  131. int main ()
  132. {
  133. if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
  134. {
  135. const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
  136. mbstate_t state;
  137. wchar_t wc;
  138. memset (&state, '\0', sizeof (mbstate_t));
  139. if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
  140. if (mbsinit (&state))
  141. return 1;
  142. }
  143. return 0;
  144. }]])],
  145. [gl_cv_func_mbrtowc_incomplete_state=yes],
  146. [gl_cv_func_mbrtowc_incomplete_state=no],
  147. [:])
  148. fi
  149. ])
  150. ])
  151. dnl Test whether mbrtowc works not worse than mbtowc.
  152. dnl Result is gl_cv_func_mbrtowc_sanitycheck.
  153. AC_DEFUN([gl_MBRTOWC_SANITYCHECK],
  154. [
  155. AC_REQUIRE([AC_PROG_CC])
  156. AC_REQUIRE([gt_LOCALE_ZH_CN])
  157. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  158. AC_CACHE_CHECK([whether mbrtowc works as well as mbtowc],
  159. [gl_cv_func_mbrtowc_sanitycheck],
  160. [
  161. dnl Initial guess, used when cross-compiling or when no suitable locale
  162. dnl is present.
  163. changequote(,)dnl
  164. case "$host_os" in
  165. # Guess no on Solaris 8.
  166. solaris2.8) gl_cv_func_mbrtowc_sanitycheck="guessing no" ;;
  167. # Guess yes otherwise.
  168. *) gl_cv_func_mbrtowc_sanitycheck="guessing yes" ;;
  169. esac
  170. changequote([,])dnl
  171. if test $LOCALE_ZH_CN != none; then
  172. AC_RUN_IFELSE(
  173. [AC_LANG_SOURCE([[
  174. #include <locale.h>
  175. #include <stdlib.h>
  176. #include <string.h>
  177. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  178. <wchar.h>.
  179. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  180. included before <wchar.h>. */
  181. #include <stddef.h>
  182. #include <stdio.h>
  183. #include <time.h>
  184. #include <wchar.h>
  185. int main ()
  186. {
  187. /* This fails on Solaris 8:
  188. mbrtowc returns 2, and sets wc to 0x00F0.
  189. mbtowc returns 4 (correct) and sets wc to 0x5EDC. */
  190. if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
  191. {
  192. char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
  193. mbstate_t state;
  194. wchar_t wc;
  195. memset (&state, '\0', sizeof (mbstate_t));
  196. if (mbrtowc (&wc, input + 3, 6, &state) != 4
  197. && mbtowc (&wc, input + 3, 6) == 4)
  198. return 1;
  199. }
  200. return 0;
  201. }]])],
  202. [gl_cv_func_mbrtowc_sanitycheck=yes],
  203. [gl_cv_func_mbrtowc_sanitycheck=no],
  204. [:])
  205. fi
  206. ])
  207. ])
  208. dnl Test whether mbrtowc supports a NULL pwc argument correctly.
  209. dnl Result is gl_cv_func_mbrtowc_null_arg1.
  210. AC_DEFUN([gl_MBRTOWC_NULL_ARG1],
  211. [
  212. AC_REQUIRE([AC_PROG_CC])
  213. AC_REQUIRE([gt_LOCALE_FR_UTF8])
  214. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  215. AC_CACHE_CHECK([whether mbrtowc handles a NULL pwc argument],
  216. [gl_cv_func_mbrtowc_null_arg1],
  217. [
  218. dnl Initial guess, used when cross-compiling or when no suitable locale
  219. dnl is present.
  220. changequote(,)dnl
  221. case "$host_os" in
  222. # Guess no on Solaris.
  223. solaris*) gl_cv_func_mbrtowc_null_arg1="guessing no" ;;
  224. # Guess yes otherwise.
  225. *) gl_cv_func_mbrtowc_null_arg1="guessing yes" ;;
  226. esac
  227. changequote([,])dnl
  228. if test $LOCALE_FR_UTF8 != none; then
  229. AC_RUN_IFELSE(
  230. [AC_LANG_SOURCE([[
  231. #include <locale.h>
  232. #include <stdlib.h>
  233. #include <string.h>
  234. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  235. <wchar.h>.
  236. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  237. included before <wchar.h>. */
  238. #include <stddef.h>
  239. #include <stdio.h>
  240. #include <time.h>
  241. #include <wchar.h>
  242. int main ()
  243. {
  244. int result = 0;
  245. if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
  246. {
  247. char input[] = "\303\237er";
  248. mbstate_t state;
  249. wchar_t wc;
  250. size_t ret;
  251. memset (&state, '\0', sizeof (mbstate_t));
  252. wc = (wchar_t) 0xBADFACE;
  253. ret = mbrtowc (&wc, input, 5, &state);
  254. if (ret != 2)
  255. result |= 1;
  256. if (!mbsinit (&state))
  257. result |= 2;
  258. memset (&state, '\0', sizeof (mbstate_t));
  259. ret = mbrtowc (NULL, input, 5, &state);
  260. if (ret != 2) /* Solaris 7 fails here: ret is -1. */
  261. result |= 4;
  262. if (!mbsinit (&state))
  263. result |= 8;
  264. }
  265. return result;
  266. }]])],
  267. [gl_cv_func_mbrtowc_null_arg1=yes],
  268. [gl_cv_func_mbrtowc_null_arg1=no],
  269. [:])
  270. fi
  271. ])
  272. ])
  273. dnl Test whether mbrtowc supports a NULL string argument correctly.
  274. dnl Result is gl_cv_func_mbrtowc_null_arg2.
  275. AC_DEFUN([gl_MBRTOWC_NULL_ARG2],
  276. [
  277. AC_REQUIRE([AC_PROG_CC])
  278. AC_REQUIRE([gt_LOCALE_FR_UTF8])
  279. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  280. AC_CACHE_CHECK([whether mbrtowc handles a NULL string argument],
  281. [gl_cv_func_mbrtowc_null_arg2],
  282. [
  283. dnl Initial guess, used when cross-compiling or when no suitable locale
  284. dnl is present.
  285. changequote(,)dnl
  286. case "$host_os" in
  287. # Guess no on OSF/1.
  288. osf*) gl_cv_func_mbrtowc_null_arg2="guessing no" ;;
  289. # Guess yes otherwise.
  290. *) gl_cv_func_mbrtowc_null_arg2="guessing yes" ;;
  291. esac
  292. changequote([,])dnl
  293. if test $LOCALE_FR_UTF8 != none; then
  294. AC_RUN_IFELSE(
  295. [AC_LANG_SOURCE([[
  296. #include <locale.h>
  297. #include <string.h>
  298. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  299. <wchar.h>.
  300. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  301. included before <wchar.h>. */
  302. #include <stddef.h>
  303. #include <stdio.h>
  304. #include <time.h>
  305. #include <wchar.h>
  306. int main ()
  307. {
  308. if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
  309. {
  310. mbstate_t state;
  311. wchar_t wc;
  312. int ret;
  313. memset (&state, '\0', sizeof (mbstate_t));
  314. wc = (wchar_t) 0xBADFACE;
  315. mbrtowc (&wc, NULL, 5, &state);
  316. /* Check that wc was not modified. */
  317. if (wc != (wchar_t) 0xBADFACE)
  318. return 1;
  319. }
  320. return 0;
  321. }]])],
  322. [gl_cv_func_mbrtowc_null_arg2=yes],
  323. [gl_cv_func_mbrtowc_null_arg2=no],
  324. [:])
  325. fi
  326. ])
  327. ])
  328. dnl Test whether mbrtowc, when parsing the end of a multibyte character,
  329. dnl correctly returns the number of bytes that were needed to complete the
  330. dnl character (not the total number of bytes of the multibyte character).
  331. dnl Result is gl_cv_func_mbrtowc_retval.
  332. AC_DEFUN([gl_MBRTOWC_RETVAL],
  333. [
  334. AC_REQUIRE([AC_PROG_CC])
  335. AC_REQUIRE([gt_LOCALE_FR_UTF8])
  336. AC_REQUIRE([gt_LOCALE_JA])
  337. AC_REQUIRE([AC_CANONICAL_HOST])
  338. AC_CACHE_CHECK([whether mbrtowc has a correct return value],
  339. [gl_cv_func_mbrtowc_retval],
  340. [
  341. dnl Initial guess, used when cross-compiling or when no suitable locale
  342. dnl is present.
  343. changequote(,)dnl
  344. case "$host_os" in
  345. # Guess no on HP-UX, Solaris, native Windows.
  346. hpux* | solaris* | mingw*) gl_cv_func_mbrtowc_retval="guessing no" ;;
  347. # Guess yes otherwise.
  348. *) gl_cv_func_mbrtowc_retval="guessing yes" ;;
  349. esac
  350. changequote([,])dnl
  351. if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none \
  352. || { case "$host_os" in mingw*) true;; *) false;; esac; }; then
  353. AC_RUN_IFELSE(
  354. [AC_LANG_SOURCE([[
  355. #include <locale.h>
  356. #include <string.h>
  357. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  358. <wchar.h>.
  359. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  360. included before <wchar.h>. */
  361. #include <stddef.h>
  362. #include <stdio.h>
  363. #include <time.h>
  364. #include <wchar.h>
  365. int main ()
  366. {
  367. int result = 0;
  368. int found_some_locale = 0;
  369. /* This fails on Solaris. */
  370. if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
  371. {
  372. char input[] = "B\303\274\303\237er"; /* "Büßer" */
  373. mbstate_t state;
  374. wchar_t wc;
  375. memset (&state, '\0', sizeof (mbstate_t));
  376. if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
  377. {
  378. input[1] = '\0';
  379. if (mbrtowc (&wc, input + 2, 5, &state) != 1)
  380. result |= 1;
  381. }
  382. found_some_locale = 1;
  383. }
  384. /* This fails on HP-UX 11.11. */
  385. if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
  386. {
  387. char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
  388. mbstate_t state;
  389. wchar_t wc;
  390. memset (&state, '\0', sizeof (mbstate_t));
  391. if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
  392. {
  393. input[1] = '\0';
  394. if (mbrtowc (&wc, input + 2, 5, &state) != 2)
  395. result |= 2;
  396. }
  397. found_some_locale = 1;
  398. }
  399. /* This fails on native Windows. */
  400. if (setlocale (LC_ALL, "Japanese_Japan.932") != NULL)
  401. {
  402. char input[] = "<\223\372\226\173\214\352>"; /* "<日本語>" */
  403. mbstate_t state;
  404. wchar_t wc;
  405. memset (&state, '\0', sizeof (mbstate_t));
  406. if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2))
  407. {
  408. input[3] = '\0';
  409. if (mbrtowc (&wc, input + 4, 4, &state) != 1)
  410. result |= 4;
  411. }
  412. found_some_locale = 1;
  413. }
  414. if (setlocale (LC_ALL, "Chinese_Taiwan.950") != NULL)
  415. {
  416. char input[] = "<\244\351\245\273\273\171>"; /* "<日本語>" */
  417. mbstate_t state;
  418. wchar_t wc;
  419. memset (&state, '\0', sizeof (mbstate_t));
  420. if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2))
  421. {
  422. input[3] = '\0';
  423. if (mbrtowc (&wc, input + 4, 4, &state) != 1)
  424. result |= 8;
  425. }
  426. found_some_locale = 1;
  427. }
  428. if (setlocale (LC_ALL, "Chinese_China.936") != NULL)
  429. {
  430. char input[] = "<\310\325\261\276\325\132>"; /* "<日本語>" */
  431. mbstate_t state;
  432. wchar_t wc;
  433. memset (&state, '\0', sizeof (mbstate_t));
  434. if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2))
  435. {
  436. input[3] = '\0';
  437. if (mbrtowc (&wc, input + 4, 4, &state) != 1)
  438. result |= 16;
  439. }
  440. found_some_locale = 1;
  441. }
  442. return (found_some_locale ? result : 77);
  443. }]])],
  444. [gl_cv_func_mbrtowc_retval=yes],
  445. [if test $? != 77; then
  446. gl_cv_func_mbrtowc_retval=no
  447. fi
  448. ],
  449. [:])
  450. fi
  451. ])
  452. ])
  453. dnl Test whether mbrtowc, when parsing a NUL character, correctly returns 0.
  454. dnl Result is gl_cv_func_mbrtowc_nul_retval.
  455. AC_DEFUN([gl_MBRTOWC_NUL_RETVAL],
  456. [
  457. AC_REQUIRE([AC_PROG_CC])
  458. AC_REQUIRE([gt_LOCALE_ZH_CN])
  459. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  460. AC_CACHE_CHECK([whether mbrtowc returns 0 when parsing a NUL character],
  461. [gl_cv_func_mbrtowc_nul_retval],
  462. [
  463. dnl Initial guess, used when cross-compiling or when no suitable locale
  464. dnl is present.
  465. changequote(,)dnl
  466. case "$host_os" in
  467. # Guess no on Solaris 8 and 9.
  468. solaris2.[89]) gl_cv_func_mbrtowc_nul_retval="guessing no" ;;
  469. # Guess yes otherwise.
  470. *) gl_cv_func_mbrtowc_nul_retval="guessing yes" ;;
  471. esac
  472. changequote([,])dnl
  473. if test $LOCALE_ZH_CN != none; then
  474. AC_RUN_IFELSE(
  475. [AC_LANG_SOURCE([[
  476. #include <locale.h>
  477. #include <string.h>
  478. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  479. <wchar.h>.
  480. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  481. included before <wchar.h>. */
  482. #include <stddef.h>
  483. #include <stdio.h>
  484. #include <time.h>
  485. #include <wchar.h>
  486. int main ()
  487. {
  488. /* This fails on Solaris 8 and 9. */
  489. if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
  490. {
  491. mbstate_t state;
  492. wchar_t wc;
  493. memset (&state, '\0', sizeof (mbstate_t));
  494. if (mbrtowc (&wc, "", 1, &state) != 0)
  495. return 1;
  496. }
  497. return 0;
  498. }]])],
  499. [gl_cv_func_mbrtowc_nul_retval=yes],
  500. [gl_cv_func_mbrtowc_nul_retval=no],
  501. [:])
  502. fi
  503. ])
  504. ])
  505. # Prerequisites of lib/mbrtowc.c.
  506. AC_DEFUN([gl_PREREQ_MBRTOWC], [
  507. :
  508. ])
  509. dnl From Paul Eggert
  510. dnl This is an override of an autoconf macro.
  511. AC_DEFUN([AC_FUNC_MBRTOWC],
  512. [
  513. dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60.
  514. AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
  515. gl_cv_func_mbrtowc,
  516. [AC_LINK_IFELSE(
  517. [AC_LANG_PROGRAM(
  518. [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
  519. included before <wchar.h>.
  520. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
  521. must be included before <wchar.h>. */
  522. #include <stddef.h>
  523. #include <stdio.h>
  524. #include <time.h>
  525. #include <wchar.h>]],
  526. [[wchar_t wc;
  527. char const s[] = "";
  528. size_t n = 1;
  529. mbstate_t state;
  530. return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])],
  531. gl_cv_func_mbrtowc=yes,
  532. gl_cv_func_mbrtowc=no)])
  533. if test $gl_cv_func_mbrtowc = yes; then
  534. AC_DEFINE([HAVE_MBRTOWC], [1],
  535. [Define to 1 if mbrtowc and mbstate_t are properly declared.])
  536. fi
  537. ])