mingw has an mbsinit() function (defined in mingw-runtime-3.15.2-1/mingwex/mbsinit.c) that always returns 1. This is inappropriate in multibyte locales, because in such locales, mbrtowc() must, when consuming the first byte of a character of 2 or more bytes, store that byte in the state in some manner.
Such locales are Japanese_Japan.932, Chinese_Taiwan.950, Chinese_China.936, present in some versions of Windows XP. Unfortunately I cannot make an autoconf test for this, because on the "Home" versions of Windows XP, such locales may not exist. But we want to get the same configuration results on both systems. So I'm applying this fix: 2011-02-13 Bruno Haible <[email protected]> mbsinit: Work around mingw bug. * m4/mbsinit.m4 (gl_FUNC_MBSINIT): Replace mbsinit also on mingw. * lib/mbsinit.c (mbsinit): Provide an alternate definition for native Windows. * doc/posix-functions/mbsinit.texi: Mention the mingw bug. --- doc/posix-functions/mbsinit.texi.orig Sun Feb 13 18:15:05 2011 +++ doc/posix-functions/mbsinit.texi Sun Feb 13 18:07:00 2011 @@ -11,6 +11,9 @@ @item This function is missing on some platforms: HP-UX 11.00, IRIX 6.5, Solaris 2.6, Interix 3.5. +@item +This function always returns 1, even in multibyte locales, on some platforms: +mingw. @end itemize Portability problems not fixed by Gnulib: --- lib/mbsinit.c.orig Sun Feb 13 18:15:05 2011 +++ lib/mbsinit.c Sun Feb 13 18:07:00 2011 @@ -22,6 +22,18 @@ #include "verify.h" +#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__ + +/* On native Windows, 'mbstate_t' is defined as 'int'. */ + +int +mbsinit (const mbstate_t *ps) +{ + return ps == NULL || *ps == 0; +} + +#else + /* Platforms that lack mbsinit() also lack mbrlen(), mbrtowc(), mbsrtowcs() and wcrtomb(), wcsrtombs(). We assume that @@ -45,3 +57,5 @@ return pstate == NULL || pstate[0] == 0; } + +#endif --- m4/mbsinit.m4.orig Sun Feb 13 18:15:06 2011 +++ m4/mbsinit.m4 Sun Feb 13 18:07:00 2011 @@ -1,4 +1,4 @@ -# mbsinit.m4 serial 4 +# mbsinit.m4 serial 5 dnl Copyright (C) 2008, 2010-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -7,6 +7,7 @@ AC_DEFUN([gl_FUNC_MBSINIT], [ AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) AC_REQUIRE([AC_TYPE_MBSTATE_T]) gl_MBSTATE_T_BROKEN @@ -17,6 +18,13 @@ else if test $REPLACE_MBSTATE_T = 1; then REPLACE_MBSINIT=1 + else + dnl On mingw, mbsinit() always returns 1, which is inappropriate for + dnl states produced by mbrtowc() for an incomplete multibyte character + dnl in multibyte locales. + case "$host_os" in + mingw*) REPLACE_MBSINIT=1 ;; + esac fi fi if test $HAVE_MBSINIT = 0 || test $REPLACE_MBSINIT = 1; then -- In memoriam Alexander Samoylovich <http://en.wikipedia.org/wiki/Alexander_Samoylovich>
