2 dnl Copyright (C) 2008, 2010-2011 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
16 AC_CHECK_DECLS([mbrlen],,, [[
17 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
19 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
20 included before <wchar.h>. */
26 if test $ac_cv_have_decl_mbrlen = yes; then
27 dnl On Minix 3.1.8, the system's <wchar.h> declares mbrlen() although
28 dnl it does not have the function. Avoid a collision with gnulib's
33 dnl Most bugs affecting the system's mbrtowc function also affect the
34 dnl mbrlen function. So override mbrlen whenever mbrtowc is overridden.
35 dnl We could also run the individual tests below; the results would be
37 if test $REPLACE_MBRTOWC = 1; then
43 dnl Test whether mbrlen puts the state into non-initial state when parsing an
44 dnl incomplete multibyte character.
45 dnl Result is gl_cv_func_mbrlen_incomplete_state.
47 AC_DEFUN([gl_MBRLEN_INCOMPLETE_STATE],
49 AC_REQUIRE([AC_PROG_CC])
50 AC_REQUIRE([gt_LOCALE_JA])
51 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
52 AC_CACHE_CHECK([whether mbrlen handles incomplete characters],
53 [gl_cv_func_mbrlen_incomplete_state],
55 dnl Initial guess, used when cross-compiling or when no suitable locale
59 # Guess no on AIX and OSF/1.
60 aix* | osf*) gl_cv_func_mbrlen_incomplete_state="guessing no" ;;
61 # Guess yes otherwise.
62 *) gl_cv_func_mbrlen_incomplete_state="guessing yes" ;;
65 if test $LOCALE_JA != none; then
70 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
72 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
73 included before <wchar.h>. */
80 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
82 const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
85 memset (&state, '\0', sizeof (mbstate_t));
86 if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
92 [gl_cv_func_mbrlen_incomplete_state=yes],
93 [gl_cv_func_mbrlen_incomplete_state=no],
99 dnl Test whether mbrlen, when parsing the end of a multibyte character,
100 dnl correctly returns the number of bytes that were needed to complete the
101 dnl character (not the total number of bytes of the multibyte character).
102 dnl Result is gl_cv_func_mbrlen_retval.
104 AC_DEFUN([gl_MBRLEN_RETVAL],
106 AC_REQUIRE([AC_PROG_CC])
107 AC_REQUIRE([gt_LOCALE_FR_UTF8])
108 AC_REQUIRE([gt_LOCALE_JA])
109 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
110 AC_CACHE_CHECK([whether mbrlen has a correct return value],
111 [gl_cv_func_mbrlen_retval],
113 dnl Initial guess, used when cross-compiling or when no suitable locale
117 # Guess no on HP-UX and Solaris.
118 hpux* | solaris*) gl_cv_func_mbrlen_retval="guessing no" ;;
119 # Guess yes otherwise.
120 *) gl_cv_func_mbrlen_retval="guessing yes" ;;
123 if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then
128 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
130 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
131 included before <wchar.h>. */
139 /* This fails on Solaris. */
140 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
142 char input[] = "B\303\274\303\237er"; /* "Büßer" */
145 memset (&state, '\0', sizeof (mbstate_t));
146 if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
149 if (mbrlen (input + 2, 5, &state) != 1)
153 /* This fails on HP-UX 11.11. */
154 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
156 char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
159 memset (&state, '\0', sizeof (mbstate_t));
160 if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
163 if (mbrlen (input + 2, 5, &state) != 2)
169 [gl_cv_func_mbrlen_retval=yes],
170 [gl_cv_func_mbrlen_retval=no],
176 dnl Test whether mbrlen, when parsing a NUL character, correctly returns 0.
177 dnl Result is gl_cv_func_mbrlen_nul_retval.
179 AC_DEFUN([gl_MBRLEN_NUL_RETVAL],
181 AC_REQUIRE([AC_PROG_CC])
182 AC_REQUIRE([gt_LOCALE_ZH_CN])
183 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
184 AC_CACHE_CHECK([whether mbrlen returns 0 when parsing a NUL character],
185 [gl_cv_func_mbrlen_nul_retval],
187 dnl Initial guess, used when cross-compiling or when no suitable locale
191 # Guess no on Solaris 9.
192 solaris2.9) gl_cv_func_mbrlen_nul_retval="guessing no" ;;
193 # Guess yes otherwise.
194 *) gl_cv_func_mbrlen_nul_retval="guessing yes" ;;
197 if test $LOCALE_ZH_CN != none; then
202 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
204 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
205 included before <wchar.h>. */
212 /* This crashes on Solaris 9 inside __mbrtowc_dense_gb18030. */
213 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
217 memset (&state, '\0', sizeof (mbstate_t));
218 if (mbrlen ("", 1, &state) != 0)
223 [gl_cv_func_mbrlen_nul_retval=yes],
224 [gl_cv_func_mbrlen_nul_retval=no],
230 # Prerequisites of lib/mbrlen.c.
231 AC_DEFUN([gl_PREREQ_MBRLEN], [