From 1b94e030d122eb05acd5054b711e7bf6d49994e3 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 13 Feb 2011 18:17:22 +0100 Subject: [PATCH] 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. (cherry picked from commit cca34e7a16b014a2429a0c0d98cfa4c935688f00) --- ChangeLog | 8 ++++++++ doc/posix-functions/mbsinit.texi | 3 +++ lib/mbsinit.c | 14 ++++++++++++++ m4/mbsinit.m4 | 10 +++++++++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 8ba516969..96262eb67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2011-02-13 Bruno Haible + 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. + +2011-02-13 Bruno Haible + mbsinit: Don't crash for a NULL argument. * lib/mbsinit.c (mbsinit): When the argument is NULL, return 1. * tests/test-mbsinit.c (mbsinit): Check this behaviour. diff --git a/doc/posix-functions/mbsinit.texi b/doc/posix-functions/mbsinit.texi index 306df87d5..a75dfa3ce 100644 --- a/doc/posix-functions/mbsinit.texi +++ b/doc/posix-functions/mbsinit.texi @@ -11,6 +11,9 @@ Portability problems fixed by Gnulib: @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: diff --git a/lib/mbsinit.c b/lib/mbsinit.c index 869c0a6ab..8ac213703 100644 --- a/lib/mbsinit.c +++ b/lib/mbsinit.c @@ -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 @@ mbsinit (const mbstate_t *ps) return pstate == NULL || pstate[0] == 0; } + +#endif diff --git a/m4/mbsinit.m4 b/m4/mbsinit.m4 index 03b31447c..47e2d14a7 100644 --- a/m4/mbsinit.m4 +++ b/m4/mbsinit.m4 @@ -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 @@ dnl with or without modifications, as long as this notice is preserved. 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 @@ AC_DEFUN([gl_FUNC_MBSINIT], 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 -- 2.11.0