2 # serial 12 -*- coding: utf-8 -*-
3 dnl Copyright (C) 2008, 2010-2024 Free Software Foundation, 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.
8 AC_DEFUN([gl_FUNC_MBRLEN],
10 AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
12 AC_REQUIRE([AC_TYPE_MBSTATE_T])
13 AC_REQUIRE([gl_FUNC_MBRTOWC])
14 AC_CHECK_FUNCS_ONCE([mbrlen])
15 if test $ac_cv_func_mbrlen = no; then
17 AC_CHECK_DECLS([mbrlen],,, [[
20 if test $ac_cv_have_decl_mbrlen = yes; then
21 dnl On Minix 3.1.8, the system's <wchar.h> declares mbrlen() although
22 dnl it does not have the function. Avoid a collision with gnulib's
27 dnl Most bugs affecting the system's mbrtowc function also affect the
28 dnl mbrlen function. So override mbrlen whenever mbrtowc is overridden.
29 dnl We could also run the individual tests below; the results would be
31 if test $REPLACE_MBRTOWC = 1; then
37 dnl Test whether mbrlen puts the state into non-initial state when parsing an
38 dnl incomplete multibyte character.
39 dnl Result is gl_cv_func_mbrlen_incomplete_state.
41 AC_DEFUN([gl_MBRLEN_INCOMPLETE_STATE],
43 AC_REQUIRE([AC_PROG_CC])
44 AC_REQUIRE([gt_LOCALE_JA])
45 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
46 AC_CACHE_CHECK([whether mbrlen handles incomplete characters],
47 [gl_cv_func_mbrlen_incomplete_state],
49 dnl Initial guess, used when cross-compiling or when no suitable locale
53 # Guess no on AIX and OSF/1.
54 aix* | osf*) gl_cv_func_mbrlen_incomplete_state="guessing no" ;;
55 # Guess yes otherwise.
56 *) gl_cv_func_mbrlen_incomplete_state="guessing yes" ;;
59 if test $LOCALE_JA != none; then
67 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
69 const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
72 memset (&state, '\0', sizeof (mbstate_t));
73 if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
79 [gl_cv_func_mbrlen_incomplete_state=yes],
80 [gl_cv_func_mbrlen_incomplete_state=no],
86 dnl Test whether mbrlen, when parsing the end of a multibyte character,
87 dnl correctly returns the number of bytes that were needed to complete the
88 dnl character (not the total number of bytes of the multibyte character).
89 dnl Result is gl_cv_func_mbrlen_retval.
91 AC_DEFUN([gl_MBRLEN_RETVAL],
93 AC_REQUIRE([AC_PROG_CC])
94 AC_REQUIRE([gt_LOCALE_FR_UTF8])
95 AC_REQUIRE([gt_LOCALE_JA])
96 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
97 AC_CACHE_CHECK([whether mbrlen has a correct return value],
98 [gl_cv_func_mbrlen_retval],
100 dnl Initial guess, used when cross-compiling or when no suitable locale
104 # Guess no on HP-UX and Solaris.
105 hpux* | solaris*) gl_cv_func_mbrlen_retval="guessing no" ;;
106 # Guess yes otherwise.
107 *) gl_cv_func_mbrlen_retval="guessing yes" ;;
110 if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then
119 /* This fails on Solaris. */
120 if (strcmp ("$LOCALE_FR_UTF8", "none") != 0
121 && setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
123 char input[] = "B\303\274\303\237er"; /* "Büßer" */
126 memset (&state, '\0', sizeof (mbstate_t));
127 if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
130 if (mbrlen (input + 2, 5, &state) != 1)
134 /* This fails on HP-UX 11.11. */
135 if (strcmp ("$LOCALE_JA", "none") != 0
136 && setlocale (LC_ALL, "$LOCALE_JA") != NULL)
138 char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
141 memset (&state, '\0', sizeof (mbstate_t));
142 if (mbrlen (input + 1, 1, &state) == (size_t)(-2))
145 if (mbrlen (input + 2, 5, &state) != 2)
151 [gl_cv_func_mbrlen_retval=yes],
152 [gl_cv_func_mbrlen_retval=no],
158 dnl Test whether mbrlen, when parsing a NUL character, correctly returns 0.
159 dnl Result is gl_cv_func_mbrlen_nul_retval.
161 AC_DEFUN([gl_MBRLEN_NUL_RETVAL],
163 AC_REQUIRE([AC_PROG_CC])
164 AC_REQUIRE([gt_LOCALE_ZH_CN])
165 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
166 AC_CACHE_CHECK([whether mbrlen returns 0 when parsing a NUL character],
167 [gl_cv_func_mbrlen_nul_retval],
169 dnl Initial guess, used when cross-compiling or when no suitable locale
173 # Guess no on Solaris 9.
174 solaris2.9) gl_cv_func_mbrlen_nul_retval="guessing no" ;;
175 # Guess yes otherwise.
176 *) gl_cv_func_mbrlen_nul_retval="guessing yes" ;;
179 if test $LOCALE_ZH_CN != none; then
187 /* This crashes on Solaris 9 inside __mbrtowc_dense_gb18030. */
188 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
192 memset (&state, '\0', sizeof (mbstate_t));
193 if (mbrlen ("", 1, &state) != 0)
198 [gl_cv_func_mbrlen_nul_retval=yes],
199 [gl_cv_func_mbrlen_nul_retval=no],
205 dnl Test whether mbrlen returns the correct value on empty input.
207 AC_DEFUN([gl_MBRLEN_EMPTY_INPUT],
209 AC_REQUIRE([AC_PROG_CC])
210 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
211 AC_CACHE_CHECK([whether mbrlen works on empty input],
212 [gl_cv_func_mbrlen_empty_input],
214 dnl Initial guess, used when cross-compiling or when no suitable locale
218 # Guess no on AIX and glibc systems.
219 aix* | *-gnu* | gnu*) gl_cv_func_mbrlen_empty_input="guessing no" ;;
220 *) gl_cv_func_mbrlen_empty_input="guessing yes" ;;
226 static mbstate_t mbs;
230 return mbrlen ("", 0, &mbs) != (size_t) -2;
232 [gl_cv_func_mbrlen_empty_input=yes],
233 [gl_cv_func_mbrlen_empty_input=no],
238 # Prerequisites of lib/mbrlen.c.
239 AC_DEFUN([gl_PREREQ_MBRLEN], [