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])
14
if test $REPLACE_MBSTATE_T = 1; then
17
AC_CHECK_FUNCS_ONCE([mbrtowc])
18
if test $ac_cv_func_mbrtowc = no; then
21
if test $HAVE_MBRTOWC != 0 && test $REPLACE_MBRTOWC != 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.])
47
if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then
54
dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that
55
dnl redefines the semantics of the given mbstate_t type.
56
dnl Result is REPLACE_MBSTATE_T.
57
dnl When this is set to 1, we replace both mbsinit() and mbrtowc(), in order to
58
dnl avoid inconsistencies.
60
AC_DEFUN([gl_MBSTATE_T_BROKEN],
62
AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
64
AC_REQUIRE([AC_TYPE_MBSTATE_T])
65
AC_CHECK_FUNCS_ONCE([mbsinit])
66
AC_CHECK_FUNCS_ONCE([mbrtowc])
67
if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then
68
gl_MBRTOWC_INCOMPLETE_STATE
69
gl_MBRTOWC_SANITYCHECK
71
case "$gl_cv_func_mbrtowc_incomplete_state" in
73
*) REPLACE_MBSTATE_T=1 ;;
75
case "$gl_cv_func_mbrtowc_sanitycheck" in
77
*) REPLACE_MBSTATE_T=1 ;;
82
if test $REPLACE_MBSTATE_T = 1; then
87
dnl Test whether mbrtowc puts the state into non-initial state when parsing an
88
dnl incomplete multibyte character.
89
dnl Result is gl_cv_func_mbrtowc_incomplete_state.
91
AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE],
93
AC_REQUIRE([AC_PROG_CC])
94
AC_REQUIRE([gt_LOCALE_JA])
95
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
96
AC_CACHE_CHECK([whether mbrtowc handles incomplete characters],
97
[gl_cv_func_mbrtowc_incomplete_state],
99
dnl Initial guess, used when cross-compiling or when no suitable locale
103
# Guess no on AIX and OSF/1.
104
osf*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;;
105
# Guess yes otherwise.
106
*) gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;;
109
if test $LOCALE_JA != none; then
116
if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
118
const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
122
memset (&state, '\0', sizeof (mbstate_t));
123
if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
124
if (mbsinit (&state))
129
[gl_cv_func_mbrtowc_incomplete_state=yes],
130
[gl_cv_func_mbrtowc_incomplete_state=no],
136
dnl Test whether mbrtowc works not worse than mbtowc.
137
dnl Result is gl_cv_func_mbrtowc_sanitycheck.
139
AC_DEFUN([gl_MBRTOWC_SANITYCHECK],
141
AC_REQUIRE([AC_PROG_CC])
142
AC_REQUIRE([gt_LOCALE_ZH_CN])
143
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
144
AC_CACHE_CHECK([whether mbrtowc works as well as mbtowc],
145
[gl_cv_func_mbrtowc_sanitycheck],
147
dnl Initial guess, used when cross-compiling or when no suitable locale
151
# Guess no on Solaris 8.
152
solaris2.8) gl_cv_func_mbrtowc_sanitycheck="guessing no" ;;
153
# Guess yes otherwise.
154
*) gl_cv_func_mbrtowc_sanitycheck="guessing yes" ;;
157
if test $LOCALE_ZH_CN != none; then
165
/* This fails on Solaris 8:
166
mbrtowc returns 2, and sets wc to 0x00F0.
167
mbtowc returns 4 (correct) and sets wc to 0x5EDC. */
168
if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
170
char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
174
memset (&state, '\0', sizeof (mbstate_t));
175
if (mbrtowc (&wc, input + 3, 6, &state) != 4
176
&& mbtowc (&wc, input + 3, 6) == 4)
181
[gl_cv_func_mbrtowc_sanitycheck=yes],
182
[gl_cv_func_mbrtowc_sanitycheck=no],
188
dnl Test whether mbrtowc supports a NULL string argument correctly.
189
dnl Result is gl_cv_func_mbrtowc_null_arg.
191
AC_DEFUN([gl_MBRTOWC_NULL_ARG],
193
AC_REQUIRE([AC_PROG_CC])
194
AC_REQUIRE([gt_LOCALE_FR_UTF8])
195
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
196
AC_CACHE_CHECK([whether mbrtowc handles a NULL string argument],
197
[gl_cv_func_mbrtowc_null_arg],
199
dnl Initial guess, used when cross-compiling or when no suitable locale
204
osf*) gl_cv_func_mbrtowc_null_arg="guessing no" ;;
205
# Guess yes otherwise.
206
*) gl_cv_func_mbrtowc_null_arg="guessing yes" ;;
209
if test $LOCALE_FR_UTF8 != none; then
216
if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
222
memset (&state, '\0', sizeof (mbstate_t));
223
wc = (wchar_t) 0xBADFACE;
224
mbrtowc (&wc, NULL, 5, &state);
225
/* Check that wc was not modified. */
226
if (wc != (wchar_t) 0xBADFACE)
230
}], [gl_cv_func_mbrtowc_null_arg=yes], [gl_cv_func_mbrtowc_null_arg=no], [:])
235
dnl Test whether mbrtowc, when parsing the end of a multibyte character,
236
dnl correctly returns the number of bytes that were needed to complete the
237
dnl character (not the total number of bytes of the multibyte character).
238
dnl Result is gl_cv_func_mbrtowc_retval.
240
AC_DEFUN([gl_MBRTOWC_RETVAL],
242
AC_REQUIRE([AC_PROG_CC])
243
AC_REQUIRE([gt_LOCALE_FR_UTF8])
244
AC_REQUIRE([gt_LOCALE_JA])
245
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
246
AC_CACHE_CHECK([whether mbrtowc has a correct return value],
247
[gl_cv_func_mbrtowc_retval],
249
dnl Initial guess, used when cross-compiling or when no suitable locale
253
# Guess no on HP-UX and Solaris.
254
hpux* | solaris*) gl_cv_func_mbrtowc_retval="guessing no" ;;
255
# Guess yes otherwise.
256
*) gl_cv_func_mbrtowc_retval="guessing yes" ;;
259
if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then
266
/* This fails on Solaris. */
267
if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
269
char input[] = "B\303\274\303\237er"; /* "Büßer" */
273
memset (&state, '\0', sizeof (mbstate_t));
274
if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
277
if (mbrtowc (&wc, input + 2, 5, &state) != 1)
281
/* This fails on HP-UX 11.11. */
282
if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
284
char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
288
memset (&state, '\0', sizeof (mbstate_t));
289
if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
292
if (mbrtowc (&wc, input + 2, 5, &state) != 2)
298
[gl_cv_func_mbrtowc_retval=yes],
299
[gl_cv_func_mbrtowc_retval=no],
305
dnl Test whether mbrtowc, when parsing a NUL character, correctly returns 0.
306
dnl Result is gl_cv_func_mbrtowc_nul_retval.
308
AC_DEFUN([gl_MBRTOWC_NUL_RETVAL],
310
AC_REQUIRE([AC_PROG_CC])
311
AC_REQUIRE([gt_LOCALE_ZH_CN])
312
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
313
AC_CACHE_CHECK([whether mbrtowc returns 0 when parsing a NUL character],
314
[gl_cv_func_mbrtowc_nul_retval],
316
dnl Initial guess, used when cross-compiling or when no suitable locale
320
# Guess no on Solaris 8 and 9.
321
solaris2.[89]) gl_cv_func_mbrtowc_nul_retval="guessing no" ;;
322
# Guess yes otherwise.
323
*) gl_cv_func_mbrtowc_nul_retval="guessing yes" ;;
326
if test $LOCALE_ZH_CN != none; then
333
/* This fails on Solaris 8 and 9. */
334
if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
339
memset (&state, '\0', sizeof (mbstate_t));
340
if (mbrtowc (&wc, "", 1, &state) != 0)
345
[gl_cv_func_mbrtowc_nul_retval=yes],
346
[gl_cv_func_mbrtowc_nul_retval=no],
352
# Prerequisites of lib/mbrtowc.c.
353
AC_DEFUN([gl_PREREQ_MBRTOWC], [
360
dnl This override of an autoconf macro can be removed when autoconf 2.60 or
361
dnl newer can be assumed everywhere.
363
m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]),[2.60]),[-1],[
364
AC_DEFUN([AC_FUNC_MBRTOWC],
366
dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60.
367
AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
371
[[#include <wchar.h>]],
376
return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])],
377
gl_cv_func_mbrtowc=yes,
378
gl_cv_func_mbrtowc=no)])
379
if test $gl_cv_func_mbrtowc = yes; then
380
AC_DEFINE([HAVE_MBRTOWC], [1],
381
[Define to 1 if mbrtowc and mbstate_t are properly declared.])