| 1 |
# mbrtowc.m4 |
| 2 |
# serial 47 |
| 3 |
dnl Copyright (C) 2001-2002, 2004-2005, 2008-2026 Free Software Foundation, |
| 4 |
dnl Inc. |
| 5 |
dnl This file is free software; the Free Software Foundation |
| 6 |
dnl gives unlimited permission to copy and/or distribute it, |
| 7 |
dnl with or without modifications, as long as this notice is preserved. |
| 8 |
dnl This file is offered as-is, without any warranty. |
| 9 |
|
| 10 |
AC_DEFUN([gl_FUNC_MBRTOWC], |
| 11 |
[ |
| 12 |
AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) |
| 13 |
AC_REQUIRE([gl_PTHREADLIB]) |
| 14 |
AC_CHECK_HEADERS_ONCE([threads.h]) |
| 15 |
|
| 16 |
AC_REQUIRE([AC_TYPE_MBSTATE_T]) |
| 17 |
gl_MBSTATE_T_BROKEN |
| 18 |
|
| 19 |
AC_CHECK_FUNCS_ONCE([mbrtowc]) |
| 20 |
if test $ac_cv_func_mbrtowc = no; then |
| 21 |
HAVE_MBRTOWC=0 |
| 22 |
AC_CHECK_DECLS([mbrtowc],,, [[ |
| 23 |
#include <wchar.h> |
| 24 |
]]) |
| 25 |
if test $ac_cv_have_decl_mbrtowc = yes; then |
| 26 |
dnl On Minix 3.1.8, the system's <wchar.h> declares mbrtowc() although |
| 27 |
dnl it does not have the function. Avoid a collision with gnulib's |
| 28 |
dnl replacement. |
| 29 |
REPLACE_MBRTOWC=1 |
| 30 |
fi |
| 31 |
else |
| 32 |
if test $REPLACE_MBSTATE_T = 1; then |
| 33 |
REPLACE_MBRTOWC=1 |
| 34 |
else |
| 35 |
gl_MBRTOWC_NULL_ARG1 |
| 36 |
gl_MBRTOWC_RETVAL |
| 37 |
gl_MBRTOWC_NUL_RETVAL |
| 38 |
gl_MBRTOWC_STORES_INCOMPLETE |
| 39 |
gl_MBRTOWC_EMPTY_INPUT |
| 40 |
gl_MBRTOWC_C_LOCALE |
| 41 |
case "$gl_cv_func_mbrtowc_null_arg1" in |
| 42 |
*yes) ;; |
| 43 |
*) AC_DEFINE([MBRTOWC_NULL_ARG1_BUG], [1], |
| 44 |
[Define if the mbrtowc function has the NULL pwc argument bug.]) |
| 45 |
REPLACE_MBRTOWC=1 |
| 46 |
;; |
| 47 |
esac |
| 48 |
case "$gl_cv_func_mbrtowc_retval" in |
| 49 |
*yes) ;; |
| 50 |
*) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1], |
| 51 |
[Define if the mbrtowc function returns a wrong return value.]) |
| 52 |
REPLACE_MBRTOWC=1 |
| 53 |
;; |
| 54 |
esac |
| 55 |
case "$gl_cv_func_mbrtowc_nul_retval" in |
| 56 |
*yes) ;; |
| 57 |
*) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1], |
| 58 |
[Define if the mbrtowc function does not return 0 for a NUL character.]) |
| 59 |
REPLACE_MBRTOWC=1 |
| 60 |
;; |
| 61 |
esac |
| 62 |
case "$gl_cv_func_mbrtowc_stores_incomplete" in |
| 63 |
*no) ;; |
| 64 |
*) AC_DEFINE([MBRTOWC_STORES_INCOMPLETE_BUG], [1], |
| 65 |
[Define if the mbrtowc function stores a wide character when reporting incomplete input.]) |
| 66 |
REPLACE_MBRTOWC=1 |
| 67 |
;; |
| 68 |
esac |
| 69 |
case "$gl_cv_func_mbrtowc_empty_input" in |
| 70 |
*yes) ;; |
| 71 |
*) AC_DEFINE([MBRTOWC_EMPTY_INPUT_BUG], [1], |
| 72 |
[Define if the mbrtowc function does not return (size_t) -2 |
| 73 |
for empty input.]) |
| 74 |
REPLACE_MBRTOWC=1 |
| 75 |
;; |
| 76 |
esac |
| 77 |
case "$gl_cv_func_mbrtowc_C_locale_sans_EILSEQ" in |
| 78 |
*yes) ;; |
| 79 |
*) AC_DEFINE([MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ], [1], |
| 80 |
[Define if the mbrtowc function may signal encoding errors in the C locale.]) |
| 81 |
REPLACE_MBRTOWC=1 |
| 82 |
;; |
| 83 |
esac |
| 84 |
fi |
| 85 |
fi |
| 86 |
if test $REPLACE_MBSTATE_T = 1; then |
| 87 |
case "$host_os" in |
| 88 |
mingw* | windows*) |
| 89 |
MBRTOWC_LIB= |
| 90 |
;; |
| 91 |
*) |
| 92 |
gl_WEAK_SYMBOLS |
| 93 |
case "$gl_cv_have_weak" in |
| 94 |
*yes) MBRTOWC_LIB= ;; |
| 95 |
*) MBRTOWC_LIB="$LIBPTHREAD" ;; |
| 96 |
esac |
| 97 |
;; |
| 98 |
esac |
| 99 |
else |
| 100 |
MBRTOWC_LIB= |
| 101 |
fi |
| 102 |
dnl MBRTOWC_LIB is expected to be '-pthread' or '-lpthread' on AIX |
| 103 |
dnl with gcc or xlc, and empty otherwise. |
| 104 |
AC_SUBST([MBRTOWC_LIB]) |
| 105 |
dnl For backward compatibility. |
| 106 |
LIB_MBRTOWC="$MBRTOWC_LIB" |
| 107 |
AC_SUBST([LIB_MBRTOWC]) |
| 108 |
]) |
| 109 |
|
| 110 |
dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that |
| 111 |
dnl redefines the semantics of the given mbstate_t type. |
| 112 |
dnl Result is REPLACE_MBSTATE_T. |
| 113 |
dnl When this is set to 1, we replace both mbsinit() and mbrtowc(), in order to |
| 114 |
dnl avoid inconsistencies. |
| 115 |
|
| 116 |
AC_DEFUN_ONCE([gl_MBSTATE_T_BROKEN], |
| 117 |
[ |
| 118 |
AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) |
| 119 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 120 |
|
| 121 |
AC_REQUIRE([AC_TYPE_MBSTATE_T]) |
| 122 |
AC_CHECK_FUNCS_ONCE([mbsinit]) |
| 123 |
AC_CHECK_FUNCS_ONCE([mbrtowc]) |
| 124 |
dnl On native Windows, we know exactly how mbsinit() behaves and don't need |
| 125 |
dnl to override it, even if - like on MSVC - mbsinit() is only defined as |
| 126 |
dnl an inline function, not as a global function. |
| 127 |
if case "$host_os" in |
| 128 |
mingw* | windows*) true ;; |
| 129 |
*) test $ac_cv_func_mbsinit = yes ;; |
| 130 |
esac \ |
| 131 |
&& test $ac_cv_func_mbrtowc = yes; then |
| 132 |
gl_MBRTOWC_INCOMPLETE_STATE |
| 133 |
gl_MBRTOWC_SANITYCHECK |
| 134 |
REPLACE_MBSTATE_T=0 |
| 135 |
case "$gl_cv_func_mbrtowc_incomplete_state" in |
| 136 |
*yes) ;; |
| 137 |
*) REPLACE_MBSTATE_T=1 ;; |
| 138 |
esac |
| 139 |
case "$gl_cv_func_mbrtowc_sanitycheck" in |
| 140 |
*yes) ;; |
| 141 |
*) REPLACE_MBSTATE_T=1 ;; |
| 142 |
esac |
| 143 |
else |
| 144 |
REPLACE_MBSTATE_T=1 |
| 145 |
fi |
| 146 |
]) |
| 147 |
|
| 148 |
dnl Test whether mbrtowc puts the state into non-initial state when parsing an |
| 149 |
dnl incomplete multibyte character. |
| 150 |
dnl Result is gl_cv_func_mbrtowc_incomplete_state. |
| 151 |
|
| 152 |
AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE], |
| 153 |
[ |
| 154 |
AC_REQUIRE([AC_PROG_CC]) |
| 155 |
AC_REQUIRE([gt_LOCALE_JA]) |
| 156 |
AC_REQUIRE([gt_LOCALE_EN_UTF8]) |
| 157 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 158 |
AC_CACHE_CHECK([whether mbrtowc handles incomplete characters], |
| 159 |
[gl_cv_func_mbrtowc_incomplete_state], |
| 160 |
[ |
| 161 |
dnl Initial guess, used when cross-compiling or when no suitable locale |
| 162 |
dnl is present. |
| 163 |
changequote(,)dnl |
| 164 |
case "$host_os" in |
| 165 |
# Guess no on AIX. |
| 166 |
aix*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;; |
| 167 |
# Guess yes otherwise. |
| 168 |
*) gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;; |
| 169 |
esac |
| 170 |
changequote([,])dnl |
| 171 |
if test $LOCALE_JA != none; then |
| 172 |
AC_RUN_IFELSE( |
| 173 |
[AC_LANG_SOURCE([[ |
| 174 |
#include <locale.h> |
| 175 |
#include <string.h> |
| 176 |
#include <wchar.h> |
| 177 |
int main () |
| 178 |
{ |
| 179 |
if (setlocale (LC_ALL, "$LOCALE_JA") != NULL) |
| 180 |
{ |
| 181 |
const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */ |
| 182 |
mbstate_t state; |
| 183 |
wchar_t wc; |
| 184 |
|
| 185 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 186 |
if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) |
| 187 |
if (mbsinit (&state)) |
| 188 |
return 2; |
| 189 |
} |
| 190 |
return 0; |
| 191 |
}]])], |
| 192 |
[gl_cv_func_mbrtowc_incomplete_state=yes], |
| 193 |
[gl_cv_func_mbrtowc_incomplete_state=no], |
| 194 |
[:]) |
| 195 |
else |
| 196 |
if test "$LOCALE_EN_UTF8" != none; then |
| 197 |
AC_RUN_IFELSE( |
| 198 |
[AC_LANG_SOURCE([[ |
| 199 |
#include <locale.h> |
| 200 |
#include <string.h> |
| 201 |
#include <wchar.h> |
| 202 |
int main () |
| 203 |
{ |
| 204 |
if (setlocale (LC_ALL, "$LOCALE_EN_UTF8") != NULL) |
| 205 |
{ |
| 206 |
const char input[] = "B\303\274\303\237er"; /* "Büßer" */ |
| 207 |
mbstate_t state; |
| 208 |
wchar_t wc; |
| 209 |
|
| 210 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 211 |
if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) |
| 212 |
if (mbsinit (&state)) |
| 213 |
return 2; |
| 214 |
} |
| 215 |
return 0; |
| 216 |
}]])], |
| 217 |
[gl_cv_func_mbrtowc_incomplete_state=yes], |
| 218 |
[gl_cv_func_mbrtowc_incomplete_state=no], |
| 219 |
[:]) |
| 220 |
fi |
| 221 |
fi |
| 222 |
]) |
| 223 |
]) |
| 224 |
|
| 225 |
dnl Test whether mbrtowc works not worse than mbtowc. |
| 226 |
dnl Result is gl_cv_func_mbrtowc_sanitycheck. |
| 227 |
|
| 228 |
AC_DEFUN([gl_MBRTOWC_SANITYCHECK], |
| 229 |
[ |
| 230 |
AC_REQUIRE([AC_PROG_CC]) |
| 231 |
AC_REQUIRE([gt_LOCALE_ZH_CN]) |
| 232 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 233 |
AC_CACHE_CHECK([whether mbrtowc works as well as mbtowc], |
| 234 |
[gl_cv_func_mbrtowc_sanitycheck], |
| 235 |
[ |
| 236 |
dnl Initial guess, used when cross-compiling or when no suitable locale |
| 237 |
dnl is present. |
| 238 |
changequote(,)dnl |
| 239 |
case "$host_os" in |
| 240 |
# Guess no on Solaris 8. |
| 241 |
solaris2.8) gl_cv_func_mbrtowc_sanitycheck="guessing no" ;; |
| 242 |
# Guess yes otherwise. |
| 243 |
*) gl_cv_func_mbrtowc_sanitycheck="guessing yes" ;; |
| 244 |
esac |
| 245 |
changequote([,])dnl |
| 246 |
if test $LOCALE_ZH_CN != none; then |
| 247 |
AC_RUN_IFELSE( |
| 248 |
[AC_LANG_SOURCE([[ |
| 249 |
#include <locale.h> |
| 250 |
#include <stdlib.h> |
| 251 |
#include <string.h> |
| 252 |
#include <wchar.h> |
| 253 |
int main () |
| 254 |
{ |
| 255 |
/* This fails on Solaris 8: |
| 256 |
mbrtowc returns 2, and sets wc to 0x00F0. |
| 257 |
mbtowc returns 4 (correct) and sets wc to 0x5EDC. */ |
| 258 |
if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL) |
| 259 |
{ |
| 260 |
char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */ |
| 261 |
mbstate_t state; |
| 262 |
wchar_t wc; |
| 263 |
|
| 264 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 265 |
if (mbrtowc (&wc, input + 3, 6, &state) != 4 |
| 266 |
&& mbtowc (&wc, input + 3, 6) == 4) |
| 267 |
return 2; |
| 268 |
} |
| 269 |
return 0; |
| 270 |
}]])], |
| 271 |
[gl_cv_func_mbrtowc_sanitycheck=yes], |
| 272 |
[gl_cv_func_mbrtowc_sanitycheck=no], |
| 273 |
[:]) |
| 274 |
fi |
| 275 |
]) |
| 276 |
]) |
| 277 |
|
| 278 |
dnl Test whether mbrtowc supports a NULL pwc argument correctly. |
| 279 |
dnl Result is gl_cv_func_mbrtowc_null_arg1. |
| 280 |
|
| 281 |
AC_DEFUN([gl_MBRTOWC_NULL_ARG1], |
| 282 |
[ |
| 283 |
AC_REQUIRE([AC_PROG_CC]) |
| 284 |
AC_REQUIRE([gt_LOCALE_EN_UTF8]) |
| 285 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 286 |
AC_CACHE_CHECK([whether mbrtowc handles a NULL pwc argument], |
| 287 |
[gl_cv_func_mbrtowc_null_arg1], |
| 288 |
[ |
| 289 |
dnl Initial guess, used when cross-compiling or when no suitable locale |
| 290 |
dnl is present. |
| 291 |
changequote(,)dnl |
| 292 |
case "$host_os" in |
| 293 |
# Guess no on Solaris. |
| 294 |
solaris*) gl_cv_func_mbrtowc_null_arg1="guessing no" ;; |
| 295 |
# Guess yes otherwise. |
| 296 |
*) gl_cv_func_mbrtowc_null_arg1="guessing yes" ;; |
| 297 |
esac |
| 298 |
changequote([,])dnl |
| 299 |
if test "$LOCALE_EN_UTF8" != none; then |
| 300 |
AC_RUN_IFELSE( |
| 301 |
[AC_LANG_SOURCE([[ |
| 302 |
#include <locale.h> |
| 303 |
#include <stdlib.h> |
| 304 |
#include <string.h> |
| 305 |
#include <wchar.h> |
| 306 |
int main () |
| 307 |
{ |
| 308 |
int result = 0; |
| 309 |
|
| 310 |
if (setlocale (LC_ALL, "$LOCALE_EN_UTF8") != NULL) |
| 311 |
{ |
| 312 |
char input[] = "\303\237er"; |
| 313 |
mbstate_t state; |
| 314 |
wchar_t wc; |
| 315 |
size_t ret; |
| 316 |
|
| 317 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 318 |
wc = (wchar_t) 0xBADFACE; |
| 319 |
ret = mbrtowc (&wc, input, 5, &state); |
| 320 |
if (ret != 2) |
| 321 |
result |= 1; |
| 322 |
if (!mbsinit (&state)) |
| 323 |
result |= 2; |
| 324 |
|
| 325 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 326 |
ret = mbrtowc (NULL, input, 5, &state); |
| 327 |
if (ret != 2) /* Solaris 7 fails here: ret is -1. */ |
| 328 |
result |= 4; |
| 329 |
if (!mbsinit (&state)) |
| 330 |
result |= 8; |
| 331 |
} |
| 332 |
return result; |
| 333 |
}]])], |
| 334 |
[gl_cv_func_mbrtowc_null_arg1=yes], |
| 335 |
[gl_cv_func_mbrtowc_null_arg1=no], |
| 336 |
[:]) |
| 337 |
fi |
| 338 |
]) |
| 339 |
]) |
| 340 |
|
| 341 |
dnl Test whether mbrtowc, when parsing the end of a multibyte character, |
| 342 |
dnl correctly returns the number of bytes that were needed to complete the |
| 343 |
dnl character (not the total number of bytes of the multibyte character). |
| 344 |
dnl Result is gl_cv_func_mbrtowc_retval. |
| 345 |
|
| 346 |
AC_DEFUN([gl_MBRTOWC_RETVAL], |
| 347 |
[ |
| 348 |
AC_REQUIRE([AC_PROG_CC]) |
| 349 |
AC_REQUIRE([gt_LOCALE_EN_UTF8]) |
| 350 |
AC_REQUIRE([gt_LOCALE_JA]) |
| 351 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 352 |
AC_CACHE_CHECK([whether mbrtowc has a correct return value], |
| 353 |
[gl_cv_func_mbrtowc_retval], |
| 354 |
[ |
| 355 |
dnl Initial guess, used when cross-compiling or when no suitable locale |
| 356 |
dnl is present. |
| 357 |
changequote(,)dnl |
| 358 |
case "$host_os" in |
| 359 |
# Guess no on HP-UX, Solaris, native Windows. |
| 360 |
hpux* | solaris* | mingw* | windows*) |
| 361 |
gl_cv_func_mbrtowc_retval="guessing no" ;; |
| 362 |
# Guess yes otherwise. |
| 363 |
*) |
| 364 |
gl_cv_func_mbrtowc_retval="guessing yes" ;; |
| 365 |
esac |
| 366 |
changequote([,])dnl |
| 367 |
if test "$LOCALE_EN_UTF8" != none || test $LOCALE_JA != none \ |
| 368 |
|| { case "$host_os" in mingw* | windows*) true;; *) false;; esac; }; then |
| 369 |
AC_RUN_IFELSE( |
| 370 |
[AC_LANG_SOURCE([[ |
| 371 |
#include <locale.h> |
| 372 |
#include <string.h> |
| 373 |
#include <wchar.h> |
| 374 |
int main () |
| 375 |
{ |
| 376 |
int result = 0; |
| 377 |
int found_some_locale = 0; |
| 378 |
/* This fails on Solaris. */ |
| 379 |
if (strcmp ("$LOCALE_EN_UTF8", "none") != 0 |
| 380 |
&& setlocale (LC_ALL, "$LOCALE_EN_UTF8") != NULL) |
| 381 |
{ |
| 382 |
char input[] = "B\303\274\303\237er"; /* "Büßer" */ |
| 383 |
mbstate_t state; |
| 384 |
wchar_t wc; |
| 385 |
|
| 386 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 387 |
if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) |
| 388 |
{ |
| 389 |
input[1] = '\0'; |
| 390 |
if (mbrtowc (&wc, input + 2, 5, &state) != 1) |
| 391 |
result |= 1; |
| 392 |
} |
| 393 |
found_some_locale = 1; |
| 394 |
} |
| 395 |
/* This fails on HP-UX 11.11. */ |
| 396 |
if (strcmp ("$LOCALE_JA", "none") != 0 |
| 397 |
&& setlocale (LC_ALL, "$LOCALE_JA") != NULL) |
| 398 |
{ |
| 399 |
char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */ |
| 400 |
mbstate_t state; |
| 401 |
wchar_t wc; |
| 402 |
|
| 403 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 404 |
if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2)) |
| 405 |
{ |
| 406 |
input[1] = '\0'; |
| 407 |
if (mbrtowc (&wc, input + 2, 5, &state) != 2) |
| 408 |
result |= 2; |
| 409 |
} |
| 410 |
found_some_locale = 1; |
| 411 |
} |
| 412 |
/* This fails on native Windows. */ |
| 413 |
if (setlocale (LC_ALL, "Japanese_Japan.932") != NULL) |
| 414 |
{ |
| 415 |
char input[] = "<\223\372\226\173\214\352>"; /* "<日本語>" */ |
| 416 |
mbstate_t state; |
| 417 |
wchar_t wc; |
| 418 |
|
| 419 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 420 |
if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2)) |
| 421 |
{ |
| 422 |
input[3] = '\0'; |
| 423 |
if (mbrtowc (&wc, input + 4, 4, &state) != 1) |
| 424 |
result |= 4; |
| 425 |
} |
| 426 |
found_some_locale = 1; |
| 427 |
} |
| 428 |
if (setlocale (LC_ALL, "Chinese_Taiwan.950") != NULL) |
| 429 |
{ |
| 430 |
char input[] = "<\244\351\245\273\273\171>"; /* "<日本語>" */ |
| 431 |
mbstate_t state; |
| 432 |
wchar_t wc; |
| 433 |
|
| 434 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 435 |
if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2)) |
| 436 |
{ |
| 437 |
input[3] = '\0'; |
| 438 |
if (mbrtowc (&wc, input + 4, 4, &state) != 1) |
| 439 |
result |= 8; |
| 440 |
} |
| 441 |
found_some_locale = 1; |
| 442 |
} |
| 443 |
if (setlocale (LC_ALL, "Chinese_China.936") != NULL) |
| 444 |
{ |
| 445 |
char input[] = "<\310\325\261\276\325\132>"; /* "<日本語>" */ |
| 446 |
mbstate_t state; |
| 447 |
wchar_t wc; |
| 448 |
|
| 449 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 450 |
if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2)) |
| 451 |
{ |
| 452 |
input[3] = '\0'; |
| 453 |
if (mbrtowc (&wc, input + 4, 4, &state) != 1) |
| 454 |
result |= 16; |
| 455 |
} |
| 456 |
found_some_locale = 1; |
| 457 |
} |
| 458 |
return (found_some_locale ? result : 77); |
| 459 |
}]])], |
| 460 |
[gl_cv_func_mbrtowc_retval=yes], |
| 461 |
[if test $? != 77; then |
| 462 |
gl_cv_func_mbrtowc_retval=no |
| 463 |
fi |
| 464 |
], |
| 465 |
[:]) |
| 466 |
fi |
| 467 |
]) |
| 468 |
]) |
| 469 |
|
| 470 |
dnl Test whether mbrtowc, when parsing a NUL character, correctly returns 0. |
| 471 |
dnl Result is gl_cv_func_mbrtowc_nul_retval. |
| 472 |
|
| 473 |
AC_DEFUN([gl_MBRTOWC_NUL_RETVAL], |
| 474 |
[ |
| 475 |
AC_REQUIRE([AC_PROG_CC]) |
| 476 |
AC_REQUIRE([gt_LOCALE_ZH_CN]) |
| 477 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 478 |
AC_CACHE_CHECK([whether mbrtowc returns 0 when parsing a NUL character], |
| 479 |
[gl_cv_func_mbrtowc_nul_retval], |
| 480 |
[ |
| 481 |
dnl Initial guess, used when cross-compiling or when no suitable locale |
| 482 |
dnl is present. |
| 483 |
changequote(,)dnl |
| 484 |
case "$host_os" in |
| 485 |
# Guess no on Solaris 8 and 9. |
| 486 |
solaris2.[89]) gl_cv_func_mbrtowc_nul_retval="guessing no" ;; |
| 487 |
# Guess yes otherwise. |
| 488 |
*) gl_cv_func_mbrtowc_nul_retval="guessing yes" ;; |
| 489 |
esac |
| 490 |
changequote([,])dnl |
| 491 |
if test $LOCALE_ZH_CN != none; then |
| 492 |
AC_RUN_IFELSE( |
| 493 |
[AC_LANG_SOURCE([[ |
| 494 |
#include <locale.h> |
| 495 |
#include <string.h> |
| 496 |
#include <wchar.h> |
| 497 |
int main () |
| 498 |
{ |
| 499 |
/* This fails on Solaris 8 and 9. */ |
| 500 |
if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL) |
| 501 |
{ |
| 502 |
mbstate_t state; |
| 503 |
wchar_t wc; |
| 504 |
|
| 505 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 506 |
if (mbrtowc (&wc, "", 1, &state) != 0) |
| 507 |
return 2; |
| 508 |
} |
| 509 |
return 0; |
| 510 |
}]])], |
| 511 |
[gl_cv_func_mbrtowc_nul_retval=yes], |
| 512 |
[gl_cv_func_mbrtowc_nul_retval=no], |
| 513 |
[:]) |
| 514 |
fi |
| 515 |
]) |
| 516 |
]) |
| 517 |
|
| 518 |
dnl Test whether mbrtowc stores a wide character when reporting incomplete |
| 519 |
dnl input. |
| 520 |
|
| 521 |
AC_DEFUN([gl_MBRTOWC_STORES_INCOMPLETE], |
| 522 |
[ |
| 523 |
AC_REQUIRE([AC_PROG_CC]) |
| 524 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 525 |
AC_CACHE_CHECK([whether mbrtowc stores incomplete characters], |
| 526 |
[gl_cv_func_mbrtowc_stores_incomplete], |
| 527 |
[ |
| 528 |
dnl Initial guess, used when cross-compiling or when no suitable locale |
| 529 |
dnl is present. |
| 530 |
changequote(,)dnl |
| 531 |
case "$host_os" in |
| 532 |
# Guess yes on native Windows. |
| 533 |
mingw* | windows*) gl_cv_func_mbrtowc_stores_incomplete="guessing yes" ;; |
| 534 |
*) gl_cv_func_mbrtowc_stores_incomplete="guessing no" ;; |
| 535 |
esac |
| 536 |
changequote([,])dnl |
| 537 |
case "$host_os" in |
| 538 |
mingw* | windows*) |
| 539 |
AC_RUN_IFELSE( |
| 540 |
[AC_LANG_SOURCE([[ |
| 541 |
#include <locale.h> |
| 542 |
#include <string.h> |
| 543 |
#include <wchar.h> |
| 544 |
int main () |
| 545 |
{ |
| 546 |
int result = 0; |
| 547 |
if (setlocale (LC_ALL, "French_France.65001") != NULL) |
| 548 |
{ |
| 549 |
wchar_t wc = (wchar_t) 0xBADFACE; |
| 550 |
mbstate_t state; |
| 551 |
|
| 552 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 553 |
if (mbrtowc (&wc, "\303", 1, &state) == (size_t)(-2) |
| 554 |
&& wc != (wchar_t) 0xBADFACE) |
| 555 |
result |= 1; |
| 556 |
} |
| 557 |
if (setlocale (LC_ALL, "Japanese_Japan.932") != NULL) |
| 558 |
{ |
| 559 |
wchar_t wc = (wchar_t) 0xBADFACE; |
| 560 |
mbstate_t state; |
| 561 |
|
| 562 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 563 |
if (mbrtowc (&wc, "\226", 1, &state) == (size_t)(-2) |
| 564 |
&& wc != (wchar_t) 0xBADFACE) |
| 565 |
result |= 2; |
| 566 |
} |
| 567 |
if (setlocale (LC_ALL, "Chinese_Taiwan.950") != NULL) |
| 568 |
{ |
| 569 |
wchar_t wc = (wchar_t) 0xBADFACE; |
| 570 |
mbstate_t state; |
| 571 |
|
| 572 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 573 |
if (mbrtowc (&wc, "\245", 1, &state) == (size_t)(-2) |
| 574 |
&& wc != (wchar_t) 0xBADFACE) |
| 575 |
result |= 4; |
| 576 |
} |
| 577 |
if (setlocale (LC_ALL, "Chinese_China.936") != NULL) |
| 578 |
{ |
| 579 |
wchar_t wc = (wchar_t) 0xBADFACE; |
| 580 |
mbstate_t state; |
| 581 |
|
| 582 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 583 |
if (mbrtowc (&wc, "\261", 1, &state) == (size_t)(-2) |
| 584 |
&& wc != (wchar_t) 0xBADFACE) |
| 585 |
result |= 8; |
| 586 |
} |
| 587 |
return result; |
| 588 |
}]])], |
| 589 |
[gl_cv_func_mbrtowc_stores_incomplete=no], |
| 590 |
[gl_cv_func_mbrtowc_stores_incomplete=yes], |
| 591 |
[:]) |
| 592 |
;; |
| 593 |
*) |
| 594 |
AC_REQUIRE([gt_LOCALE_EN_UTF8]) |
| 595 |
if test "$LOCALE_EN_UTF8" != none; then |
| 596 |
AC_RUN_IFELSE( |
| 597 |
[AC_LANG_SOURCE([[ |
| 598 |
#include <locale.h> |
| 599 |
#include <string.h> |
| 600 |
#include <wchar.h> |
| 601 |
int main () |
| 602 |
{ |
| 603 |
if (setlocale (LC_ALL, "$LOCALE_EN_UTF8") != NULL) |
| 604 |
{ |
| 605 |
wchar_t wc = (wchar_t) 0xBADFACE; |
| 606 |
mbstate_t state; |
| 607 |
|
| 608 |
memset (&state, '\0', sizeof (mbstate_t)); |
| 609 |
if (mbrtowc (&wc, "\303", 1, &state) == (size_t)(-2) |
| 610 |
&& wc != (wchar_t) 0xBADFACE) |
| 611 |
return 1; |
| 612 |
} |
| 613 |
return 0; |
| 614 |
}]])], |
| 615 |
[gl_cv_func_mbrtowc_stores_incomplete=no], |
| 616 |
[gl_cv_func_mbrtowc_stores_incomplete=yes], |
| 617 |
[:]) |
| 618 |
fi |
| 619 |
;; |
| 620 |
esac |
| 621 |
]) |
| 622 |
]) |
| 623 |
|
| 624 |
dnl Test whether mbrtowc returns the correct value on empty input. |
| 625 |
|
| 626 |
AC_DEFUN([gl_MBRTOWC_EMPTY_INPUT], |
| 627 |
[ |
| 628 |
AC_REQUIRE([AC_PROG_CC]) |
| 629 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 630 |
AC_CACHE_CHECK([whether mbrtowc works on empty input], |
| 631 |
[gl_cv_func_mbrtowc_empty_input], |
| 632 |
[AC_RUN_IFELSE( |
| 633 |
[AC_LANG_SOURCE([[ |
| 634 |
#include <wchar.h> |
| 635 |
static wchar_t wc; |
| 636 |
static mbstate_t mbs; |
| 637 |
int |
| 638 |
main (void) |
| 639 |
{ |
| 640 |
return mbrtowc (&wc, "", 0, &mbs) != (size_t) -2; |
| 641 |
}]])], |
| 642 |
[gl_cv_func_mbrtowc_empty_input=yes], |
| 643 |
[gl_cv_func_mbrtowc_empty_input=no], |
| 644 |
[case "$host_os" in |
| 645 |
# Guess no on AIX and glibc systems. |
| 646 |
aix* | *-gnu* | gnu*) gl_cv_func_mbrtowc_empty_input="guessing no" ;; |
| 647 |
# Guess no on Android. |
| 648 |
linux*-android*) gl_cv_func_mbrtowc_empty_input="guessing no" ;; |
| 649 |
# Guess no on native Windows. |
| 650 |
mingw* | windows*) gl_cv_func_mbrtowc_empty_input="guessing no" ;; |
| 651 |
*) gl_cv_func_mbrtowc_empty_input="guessing yes" ;; |
| 652 |
esac |
| 653 |
]) |
| 654 |
]) |
| 655 |
]) |
| 656 |
|
| 657 |
dnl Test whether mbrtowc reports encoding errors in the C locale. |
| 658 |
dnl Although POSIX was never intended to allow this, the GNU C Library |
| 659 |
dnl and other implementations do it. See: |
| 660 |
dnl https://sourceware.org/PR19932 |
| 661 |
dnl POSIX has now clarified it: |
| 662 |
dnl <https://pubs.opengroup.org/onlinepubs/9699919799/functions/mbrtowc.html> |
| 663 |
dnl says: "In the POSIX locale an [EILSEQ] error cannot occur since all byte |
| 664 |
dnl values are valid characters." |
| 665 |
|
| 666 |
AC_DEFUN([gl_MBRTOWC_C_LOCALE], |
| 667 |
[ |
| 668 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 669 |
AC_CACHE_CHECK([whether the C locale is free of encoding errors], |
| 670 |
[gl_cv_func_mbrtowc_C_locale_sans_EILSEQ], |
| 671 |
[AC_RUN_IFELSE( |
| 672 |
[AC_LANG_PROGRAM( |
| 673 |
[[#include <limits.h> |
| 674 |
#include <locale.h> |
| 675 |
#include <wchar.h> |
| 676 |
]], [[ |
| 677 |
int i; |
| 678 |
char *locale = setlocale (LC_ALL, "C"); |
| 679 |
if (! locale) |
| 680 |
return 2; |
| 681 |
for (i = CHAR_MIN; i <= CHAR_MAX; i++) |
| 682 |
{ |
| 683 |
char c = i; |
| 684 |
wchar_t wc; |
| 685 |
mbstate_t mbs = { 0, }; |
| 686 |
size_t ss = mbrtowc (&wc, &c, 1, &mbs); |
| 687 |
if (1 < ss) |
| 688 |
return 3; |
| 689 |
} |
| 690 |
return 0; |
| 691 |
]])], |
| 692 |
[gl_cv_func_mbrtowc_C_locale_sans_EILSEQ=yes], |
| 693 |
[gl_cv_func_mbrtowc_C_locale_sans_EILSEQ=no], |
| 694 |
[case "$host_os" in |
| 695 |
# Guess yes on native Windows. |
| 696 |
mingw* | windows*) gl_cv_func_mbrtowc_C_locale_sans_EILSEQ="guessing yes" ;; |
| 697 |
*) gl_cv_func_mbrtowc_C_locale_sans_EILSEQ="$gl_cross_guess_normal" ;; |
| 698 |
esac |
| 699 |
]) |
| 700 |
]) |
| 701 |
]) |
| 702 |
|
| 703 |
# Prerequisites of lib/mbrtowc.c and lib/lc-charset-dispatch.c. |
| 704 |
AC_DEFUN([gl_PREREQ_MBRTOWC], [ |
| 705 |
AC_REQUIRE([AC_C_INLINE]) |
| 706 |
: |
| 707 |
]) |
| 708 |
|
| 709 |
# Prerequisites of lib/mbtowc-lock.c. |
| 710 |
AC_DEFUN([gl_PREREQ_MBTOWC_LOCK], |
| 711 |
[ |
| 712 |
gl_VISIBILITY |
| 713 |
]) |
| 714 |
|
| 715 |
|
| 716 |
dnl From Paul Eggert |
| 717 |
|
| 718 |
dnl This is an override of an autoconf macro. |
| 719 |
|
| 720 |
AC_DEFUN([AC_FUNC_MBRTOWC], |
| 721 |
[ |
| 722 |
dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60. |
| 723 |
AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared], |
| 724 |
[gl_cv_func_mbrtowc], |
| 725 |
[AC_LINK_IFELSE( |
| 726 |
[AC_LANG_PROGRAM( |
| 727 |
[[#include <wchar.h>]], |
| 728 |
[[wchar_t wc; |
| 729 |
char const s[] = ""; |
| 730 |
size_t n = 1; |
| 731 |
mbstate_t state; |
| 732 |
return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])], |
| 733 |
[gl_cv_func_mbrtowc=yes], |
| 734 |
[gl_cv_func_mbrtowc=no])]) |
| 735 |
if test $gl_cv_func_mbrtowc = yes; then |
| 736 |
AC_DEFINE([HAVE_MBRTOWC], [1], |
| 737 |
[Define to 1 if mbrtowc and mbstate_t are properly declared.]) |
| 738 |
fi |
| 739 |
]) |