2 dnl Copyright (C) 2001-2002, 2004-2005, 2008-2010 Free Software Foundation,
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.
8 AC_DEFUN([gl_FUNC_MBRTOWC],
10 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
12 AC_REQUIRE([AC_TYPE_MBSTATE_T])
15 AC_CHECK_FUNCS_ONCE([mbrtowc])
16 if test $ac_cv_func_mbrtowc = no; then
19 if test $REPLACE_MBSTATE_T = 1; then
25 case "$gl_cv_func_mbrtowc_null_arg" in
27 *) AC_DEFINE([MBRTOWC_NULL_ARG_BUG], [1],
28 [Define if the mbrtowc function has the NULL string argument bug.])
32 case "$gl_cv_func_mbrtowc_retval" in
34 *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1],
35 [Define if the mbrtowc function returns a wrong return value.])
39 case "$gl_cv_func_mbrtowc_nul_retval" in
41 *) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1],
42 [Define if the mbrtowc function does not return 0 for a NUL character.])
48 if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then
55 dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that
56 dnl redefines the semantics of the given mbstate_t type.
57 dnl Result is REPLACE_MBSTATE_T.
58 dnl When this is set to 1, we replace both mbsinit() and mbrtowc(), in order to
59 dnl avoid inconsistencies.
61 AC_DEFUN([gl_MBSTATE_T_BROKEN],
63 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
65 AC_REQUIRE([AC_TYPE_MBSTATE_T])
66 AC_CHECK_FUNCS_ONCE([mbsinit])
67 AC_CHECK_FUNCS_ONCE([mbrtowc])
68 if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then
69 gl_MBRTOWC_INCOMPLETE_STATE
70 gl_MBRTOWC_SANITYCHECK
72 case "$gl_cv_func_mbrtowc_incomplete_state" in
74 *) REPLACE_MBSTATE_T=1 ;;
76 case "$gl_cv_func_mbrtowc_sanitycheck" in
78 *) REPLACE_MBSTATE_T=1 ;;
83 if test $REPLACE_MBSTATE_T = 1; then
88 dnl Test whether mbrtowc puts the state into non-initial state when parsing an
89 dnl incomplete multibyte character.
90 dnl Result is gl_cv_func_mbrtowc_incomplete_state.
92 AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE],
94 AC_REQUIRE([AC_PROG_CC])
95 AC_REQUIRE([gt_LOCALE_JA])
96 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
97 AC_CACHE_CHECK([whether mbrtowc handles incomplete characters],
98 [gl_cv_func_mbrtowc_incomplete_state],
100 dnl Initial guess, used when cross-compiling or when no suitable locale
104 # Guess no on AIX and OSF/1.
105 aix* | osf*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;;
106 # Guess yes otherwise.
107 *) gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;;
110 if test $LOCALE_JA != none; then
115 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
117 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
118 included before <wchar.h>. */
125 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
127 const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
131 memset (&state, '\0', sizeof (mbstate_t));
132 if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
133 if (mbsinit (&state))
138 [gl_cv_func_mbrtowc_incomplete_state=yes],
139 [gl_cv_func_mbrtowc_incomplete_state=no],
145 dnl Test whether mbrtowc works not worse than mbtowc.
146 dnl Result is gl_cv_func_mbrtowc_sanitycheck.
148 AC_DEFUN([gl_MBRTOWC_SANITYCHECK],
150 AC_REQUIRE([AC_PROG_CC])
151 AC_REQUIRE([gt_LOCALE_ZH_CN])
152 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
153 AC_CACHE_CHECK([whether mbrtowc works as well as mbtowc],
154 [gl_cv_func_mbrtowc_sanitycheck],
156 dnl Initial guess, used when cross-compiling or when no suitable locale
160 # Guess no on Solaris 8.
161 solaris2.8) gl_cv_func_mbrtowc_sanitycheck="guessing no" ;;
162 # Guess yes otherwise.
163 *) gl_cv_func_mbrtowc_sanitycheck="guessing yes" ;;
166 if test $LOCALE_ZH_CN != none; then
172 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
174 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
175 included before <wchar.h>. */
182 /* This fails on Solaris 8:
183 mbrtowc returns 2, and sets wc to 0x00F0.
184 mbtowc returns 4 (correct) and sets wc to 0x5EDC. */
185 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
187 char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
191 memset (&state, '\0', sizeof (mbstate_t));
192 if (mbrtowc (&wc, input + 3, 6, &state) != 4
193 && mbtowc (&wc, input + 3, 6) == 4)
198 [gl_cv_func_mbrtowc_sanitycheck=yes],
199 [gl_cv_func_mbrtowc_sanitycheck=no],
205 dnl Test whether mbrtowc supports a NULL string argument correctly.
206 dnl Result is gl_cv_func_mbrtowc_null_arg.
208 AC_DEFUN([gl_MBRTOWC_NULL_ARG],
210 AC_REQUIRE([AC_PROG_CC])
211 AC_REQUIRE([gt_LOCALE_FR_UTF8])
212 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
213 AC_CACHE_CHECK([whether mbrtowc handles a NULL string argument],
214 [gl_cv_func_mbrtowc_null_arg],
216 dnl Initial guess, used when cross-compiling or when no suitable locale
221 osf*) gl_cv_func_mbrtowc_null_arg="guessing no" ;;
222 # Guess yes otherwise.
223 *) gl_cv_func_mbrtowc_null_arg="guessing yes" ;;
226 if test $LOCALE_FR_UTF8 != none; then
231 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
233 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
234 included before <wchar.h>. */
241 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
247 memset (&state, '\0', sizeof (mbstate_t));
248 wc = (wchar_t) 0xBADFACE;
249 mbrtowc (&wc, NULL, 5, &state);
250 /* Check that wc was not modified. */
251 if (wc != (wchar_t) 0xBADFACE)
256 [gl_cv_func_mbrtowc_null_arg=yes],
257 [gl_cv_func_mbrtowc_null_arg=no],
263 dnl Test whether mbrtowc, when parsing the end of a multibyte character,
264 dnl correctly returns the number of bytes that were needed to complete the
265 dnl character (not the total number of bytes of the multibyte character).
266 dnl Result is gl_cv_func_mbrtowc_retval.
268 AC_DEFUN([gl_MBRTOWC_RETVAL],
270 AC_REQUIRE([AC_PROG_CC])
271 AC_REQUIRE([gt_LOCALE_FR_UTF8])
272 AC_REQUIRE([gt_LOCALE_JA])
273 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
274 AC_CACHE_CHECK([whether mbrtowc has a correct return value],
275 [gl_cv_func_mbrtowc_retval],
277 dnl Initial guess, used when cross-compiling or when no suitable locale
281 # Guess no on HP-UX and Solaris.
282 hpux* | solaris*) gl_cv_func_mbrtowc_retval="guessing no" ;;
283 # Guess yes otherwise.
284 *) gl_cv_func_mbrtowc_retval="guessing yes" ;;
287 if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then
292 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
294 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
295 included before <wchar.h>. */
303 /* This fails on Solaris. */
304 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
306 char input[] = "B\303\274\303\237er"; /* "Büßer" */
310 memset (&state, '\0', sizeof (mbstate_t));
311 if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
314 if (mbrtowc (&wc, input + 2, 5, &state) != 1)
318 /* This fails on HP-UX 11.11. */
319 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
321 char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
325 memset (&state, '\0', sizeof (mbstate_t));
326 if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
329 if (mbrtowc (&wc, input + 2, 5, &state) != 2)
335 [gl_cv_func_mbrtowc_retval=yes],
336 [gl_cv_func_mbrtowc_retval=no],
342 dnl Test whether mbrtowc, when parsing a NUL character, correctly returns 0.
343 dnl Result is gl_cv_func_mbrtowc_nul_retval.
345 AC_DEFUN([gl_MBRTOWC_NUL_RETVAL],
347 AC_REQUIRE([AC_PROG_CC])
348 AC_REQUIRE([gt_LOCALE_ZH_CN])
349 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
350 AC_CACHE_CHECK([whether mbrtowc returns 0 when parsing a NUL character],
351 [gl_cv_func_mbrtowc_nul_retval],
353 dnl Initial guess, used when cross-compiling or when no suitable locale
357 # Guess no on Solaris 8 and 9.
358 solaris2.[89]) gl_cv_func_mbrtowc_nul_retval="guessing no" ;;
359 # Guess yes otherwise.
360 *) gl_cv_func_mbrtowc_nul_retval="guessing yes" ;;
363 if test $LOCALE_ZH_CN != none; then
368 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
370 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
371 included before <wchar.h>. */
378 /* This fails on Solaris 8 and 9. */
379 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
384 memset (&state, '\0', sizeof (mbstate_t));
385 if (mbrtowc (&wc, "", 1, &state) != 0)
390 [gl_cv_func_mbrtowc_nul_retval=yes],
391 [gl_cv_func_mbrtowc_nul_retval=no],
397 # Prerequisites of lib/mbrtowc.c.
398 AC_DEFUN([gl_PREREQ_MBRTOWC], [
405 dnl This is an override of an autoconf macro.
407 AC_DEFUN([AC_FUNC_MBRTOWC],
409 dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60.
410 AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
414 [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
415 included before <wchar.h>.
416 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
417 must be included before <wchar.h>. */
421 #include <wchar.h>]],
426 return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])],
427 gl_cv_func_mbrtowc=yes,
428 gl_cv_func_mbrtowc=no)])
429 if test $gl_cv_func_mbrtowc = yes; then
430 AC_DEFINE([HAVE_MBRTOWC], [1],
431 [Define to 1 if mbrtowc and mbstate_t are properly declared.])