2 dnl Copyright (C) 2008, 2009 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_MBRLEN],
9 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
11 AC_REQUIRE([AC_TYPE_MBSTATE_T])
12 AC_REQUIRE([gl_FUNC_MBRTOWC])
13 AC_CHECK_FUNCS_ONCE([mbrlen])
14 if test $ac_cv_func_mbrlen = no; then
17 dnl Most bugs affecting the system's mbrtowc function also affect the
18 dnl mbrlen function. So override mbrlen whenever mbrtowc is overridden.
19 dnl We could also run the individual tests below; the results would be
21 if test $REPLACE_MBRTOWC = 1; then
25 if test $HAVE_MBRLEN = 0 || test $REPLACE_MBRLEN = 1; then
32 dnl Test whether mbrlen puts the state into non-initial state when parsing an
33 dnl incomplete multibyte character.
34 dnl Result is gl_cv_func_mbrlen_incomplete_state.
36 AC_DEFUN([gl_MBRLEN_INCOMPLETE_STATE],
38 AC_REQUIRE([AC_PROG_CC])
39 AC_REQUIRE([gt_LOCALE_JA])
40 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
41 AC_CACHE_CHECK([whether mbrlen handles incomplete characters],
42 [gl_cv_func_mbrlen_incomplete_state],
44 dnl Initial guess, used when cross-compiling or when no suitable locale
48 # Guess no on AIX and OSF/1.
49 osf*) gl_cv_func_mbrlen_incomplete_state="guessing no" ;;
50 # Guess yes otherwise.
51 *) gl_cv_func_mbrlen_incomplete_state="guessing yes" ;;
54 if test $LOCALE_JA != none; then
61 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
63 const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
66 memset (&state, '\0', sizeof (mbstate_t));
67 if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
73 [gl_cv_func_mbrlen_incomplete_state=yes],
74 [gl_cv_func_mbrlen_incomplete_state=no],
80 dnl Test whether mbrlen, when parsing the end of a multibyte character,
81 dnl correctly returns the number of bytes that were needed to complete the
82 dnl character (not the total number of bytes of the multibyte character).
83 dnl Result is gl_cv_func_mbrlen_retval.
85 AC_DEFUN([gl_MBRLEN_RETVAL],
87 AC_REQUIRE([AC_PROG_CC])
88 AC_REQUIRE([gt_LOCALE_FR_UTF8])
89 AC_REQUIRE([gt_LOCALE_JA])
90 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
91 AC_CACHE_CHECK([whether mbrlen has a correct return value],
92 [gl_cv_func_mbrlen_retval],
94 dnl Initial guess, used when cross-compiling or when no suitable locale
98 # Guess no on HP-UX and Solaris.
99 hpux* | solaris*) gl_cv_func_mbrlen_retval="guessing no" ;;
100 # Guess yes otherwise.
101 *) gl_cv_func_mbrlen_retval="guessing yes" ;;
104 if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then
111 /* This fails on Solaris. */
112 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
114 char input[] = "B\303\274\303\237er"; /* "Büßer" */
117 memset (&state, '\0', sizeof (mbstate_t));
118 if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
121 if (mbrlen (input + 2, 5, &state) != 1)
125 /* This fails on HP-UX 11.11. */
126 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
128 char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
131 memset (&state, '\0', sizeof (mbstate_t));
132 if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
135 if (mbrlen (input + 2, 5, &state) != 2)
141 [gl_cv_func_mbrlen_retval=yes],
142 [gl_cv_func_mbrlen_retval=no],
148 dnl Test whether mbrlen, when parsing a NUL character, correctly returns 0.
149 dnl Result is gl_cv_func_mbrlen_nul_retval.
151 AC_DEFUN([gl_MBRLEN_NUL_RETVAL],
153 AC_REQUIRE([AC_PROG_CC])
154 AC_REQUIRE([gt_LOCALE_ZH_CN])
155 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
156 AC_CACHE_CHECK([whether mbrlen returns 0 when parsing a NUL character],
157 [gl_cv_func_mbrlen_nul_retval],
159 dnl Initial guess, used when cross-compiling or when no suitable locale
163 # Guess no on Solaris 9.
164 solaris2.9) gl_cv_func_mbrlen_nul_retval="guessing no" ;;
165 # Guess yes otherwise.
166 *) gl_cv_func_mbrlen_nul_retval="guessing yes" ;;
169 if test $LOCALE_ZH_CN != none; then
176 /* This crashes on Solaris 9 inside __mbrtowc_dense_gb18030. */
177 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
181 memset (&state, '\0', sizeof (mbstate_t));
182 if (mbrlen ("", 1, &state) != 0)
187 [gl_cv_func_mbrlen_nul_retval=yes],
188 [gl_cv_func_mbrlen_nul_retval=no],
194 # Prerequisites of lib/mbrlen.c.
195 AC_DEFUN([gl_PREREQ_MBRLEN], [