mbrtowc.m4 18 KB

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