# HG changeset patch # User Bruno Haible # Date 1297621782 -3600 # Node ID dceb65f713b56258fef434df927172de1029922c # Parent 38e1a5ec714d35056111c6a65454cb1db296ce46 mbrtowc: Work around native Windows bug. * m4/mbrtowc.m4 (gl_MBRTOWC_RETVAL): Detect native Windows bug. Use the guess when no suitable locale for testing was found. * doc/posix-functions/mbrtowc.texi: Mention the native Windows bug. diff -r 38e1a5ec714d -r dceb65f713b5 ChangeLog --- a/ChangeLog Sun Feb 13 18:17:22 2011 +0100 +++ b/ChangeLog Sun Feb 13 19:29:42 2011 +0100 @@ -1,3 +1,10 @@ +2011-02-13 Bruno Haible + + mbrtowc: Work around native Windows bug. + * m4/mbrtowc.m4 (gl_MBRTOWC_RETVAL): Detect native Windows bug. Use the + guess when no suitable locale for testing was found. + * doc/posix-functions/mbrtowc.texi: Mention the native Windows bug. + 2011-02-13 Bruno Haible mbsinit: Work around mingw bug. diff -r 38e1a5ec714d -r dceb65f713b5 doc/posix-functions/mbrtowc.texi --- a/doc/posix-functions/mbrtowc.texi Sun Feb 13 18:17:22 2011 +0100 +++ b/doc/posix-functions/mbrtowc.texi Sun Feb 13 19:29:42 2011 +0100 @@ -30,7 +30,7 @@ This function returns the total number of bytes that make up the multibyte character, not the number of bytes that were needed to complete the multibyte character, on some platforms: -HP-UX 11.11, Solaris 11 2010-11. +HP-UX 11.11, Solaris 11 2010-11, mingw. @item This function may not return 0 when parsing the NUL character on some platforms: Solaris 9. diff -r 38e1a5ec714d -r dceb65f713b5 m4/mbrtowc.m4 --- a/m4/mbrtowc.m4 Sun Feb 13 18:17:22 2011 +0100 +++ b/m4/mbrtowc.m4 Sun Feb 13 19:29:42 2011 +0100 @@ -1,4 +1,4 @@ -# mbrtowc.m4 serial 21 +# mbrtowc.m4 serial 22 dnl Copyright (C) 2001-2002, 2004-2005, 2008-2011 Free Software Foundation, dnl Inc. dnl This file is free software; the Free Software Foundation @@ -348,7 +348,7 @@ AC_REQUIRE([AC_PROG_CC]) AC_REQUIRE([gt_LOCALE_FR_UTF8]) AC_REQUIRE([gt_LOCALE_JA]) - AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_REQUIRE([AC_CANONICAL_HOST]) AC_CACHE_CHECK([whether mbrtowc has a correct return value], [gl_cv_func_mbrtowc_retval], [ @@ -356,13 +356,14 @@ dnl is present. changequote(,)dnl case "$host_os" in - # Guess no on HP-UX and Solaris. - hpux* | solaris*) gl_cv_func_mbrtowc_retval="guessing no" ;; - # Guess yes otherwise. - *) gl_cv_func_mbrtowc_retval="guessing yes" ;; + # Guess no on HP-UX, Solaris, native Windows. + hpux* | solaris* | mingw*) gl_cv_func_mbrtowc_retval="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_mbrtowc_retval="guessing yes" ;; esac changequote([,])dnl - if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none; then + if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none \ + || { case "$host_os" in mingw*) true;; *) false;; esac; }; then AC_RUN_IFELSE( [AC_LANG_SOURCE([[ #include @@ -378,6 +379,7 @@ int main () { int result = 0; + int found_some_locale = 0; /* This fails on Solaris. */ if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) { @@ -392,6 +394,7 @@ if (mbrtowc (&wc, input + 2, 5, &state) != 1) result |= 1; } + found_some_locale = 1; } /* This fails on HP-UX 11.11. */ if (setlocale (LC_ALL, "$LOCALE_JA") != NULL) @@ -407,11 +410,61 @@ if (mbrtowc (&wc, input + 2, 5, &state) != 2) result |= 2; } + found_some_locale = 1; } - return result; + /* This fails on native Windows. */ + if (setlocale (LC_ALL, "Japanese_Japan.932") != NULL) + { + char input[] = "<\223\372\226\173\214\352>"; /* "<日本語>" */ + mbstate_t state; + wchar_t wc; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2)) + { + input[3] = '\0'; + if (mbrtowc (&wc, input + 4, 4, &state) != 1) + result |= 4; + } + found_some_locale = 1; + } + if (setlocale (LC_ALL, "Chinese_Taiwan.950") != NULL) + { + char input[] = "<\244\351\245\273\273\171>"; /* "<日本語>" */ + mbstate_t state; + wchar_t wc; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2)) + { + input[3] = '\0'; + if (mbrtowc (&wc, input + 4, 4, &state) != 1) + result |= 8; + } + found_some_locale = 1; + } + if (setlocale (LC_ALL, "Chinese_China.936") != NULL) + { + char input[] = "<\310\325\261\276\325\132>"; /* "<日本語>" */ + mbstate_t state; + wchar_t wc; + + memset (&state, '\0', sizeof (mbstate_t)); + if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2)) + { + input[3] = '\0'; + if (mbrtowc (&wc, input + 4, 4, &state) != 1) + result |= 16; + } + found_some_locale = 1; + } + return (found_some_locale ? result : 77); }]])], [gl_cv_func_mbrtowc_retval=yes], - [gl_cv_func_mbrtowc_retval=no], + [if test $? != 77; then + gl_cv_func_mbrtowc_retval=no + fi + ], [:]) fi ])