[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
mbrtowc: work around native Windows bug
From: |
Bruno Haible |
Subject: |
mbrtowc: work around native Windows bug |
Date: |
Sun, 13 Feb 2011 20:26:35 +0100 |
User-agent: |
KMail/1.9.9 |
On native Windows (mingw and msvc), mbrtowc has an incorrect return value
when processing the second byte of a 2-byte character.
This fixes it by enabling the workaround in lib/mbrtowc.c.
2011-02-13 Bruno Haible <address@hidden>
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.
--- doc/posix-functions/mbrtowc.texi.orig Sun Feb 13 19:26:40 2011
+++ doc/posix-functions/mbrtowc.texi Sun Feb 13 18:27:47 2011
@@ -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.
--- m4/mbrtowc.m4.orig Sun Feb 13 19:26:40 2011
+++ m4/mbrtowc.m4 Sun Feb 13 19:05:01 2011
@@ -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 <locale.h>
@@ -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
])
--
In memoriam Alexander Samoylovich
<http://en.wikipedia.org/wiki/Alexander_Samoylovich>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- mbrtowc: work around native Windows bug,
Bruno Haible <=