summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--doc/posix-functions/mbsrtowcs.texi3
-rw-r--r--m4/mbsrtowcs.m492
-rw-r--r--modules/mbsrtowcs3
4 files changed, 106 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index d8b1e5210d..70f5580cca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2008-12-21 Bruno Haible <bruno@clisp.org>
+ Work around mbsrtowcs bug.
+ * m4/mbsrtowcs.m4 (gl_MBSRTOWCS_WORKS): New macro.
+ (gl_FUNC_MBSRTOWCS): Invoke it.
+ * modules/mbsrtowcs (Files): Add m4/locale-fr.m4, m4/locale-ja.m4,
+ m4/locale-zh.m4.
+ * doc/posix-functions/mbsrtowcs.texi: Document the bug.
+
+2008-12-21 Bruno Haible <bruno@clisp.org>
+
* tests/test-mbsrtowcs.c (main): Execute the loop also for unlimited=1.
2008-12-21 Bruno Haible <bruno@clisp.org>
diff --git a/doc/posix-functions/mbsrtowcs.texi b/doc/posix-functions/mbsrtowcs.texi
index e201c67225..bc4e91475d 100644
--- a/doc/posix-functions/mbsrtowcs.texi
+++ b/doc/posix-functions/mbsrtowcs.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, mingw, Interix 3.5.
+@item
+This function does not work on some platforms:
+HP-UX 11, Solaris 10.
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/m4/mbsrtowcs.m4 b/m4/mbsrtowcs.m4
index 58ae2c683c..d18ef13ee5 100644
--- a/m4/mbsrtowcs.m4
+++ b/m4/mbsrtowcs.m4
@@ -1,4 +1,4 @@
-# mbsrtowcs.m4 serial 2
+# mbsrtowcs.m4 serial 3
dnl Copyright (C) 2008 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -17,6 +17,13 @@ AC_DEFUN([gl_FUNC_MBSRTOWCS],
if test $ac_cv_func_mbsrtowcs = no; then
HAVE_MBSRTOWCS=0
fi
+ if test $HAVE_MBSRTOWCS != 0 && test $REPLACE_MBSRTOWCS != 1; then
+ gl_MBSRTOWCS_WORKS
+ case "$gl_cv_func_mbsrtowcs_works" in
+ *yes) ;;
+ *) REPLACE_MBSRTOWCS=1 ;;
+ esac
+ fi
if test $HAVE_MBSRTOWCS = 0 || test $REPLACE_MBSRTOWCS = 1; then
gl_REPLACE_WCHAR_H
AC_LIBOBJ([mbsrtowcs])
@@ -24,6 +31,89 @@ AC_DEFUN([gl_FUNC_MBSRTOWCS],
fi
])
+dnl Test whether mbsrtowcs works.
+dnl Result is gl_cv_func_mbsrtowcs_works.
+
+AC_DEFUN([gl_MBSRTOWCS_WORKS],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([gt_LOCALE_FR_UTF8])
+ AC_REQUIRE([gt_LOCALE_JA])
+ AC_REQUIRE([gt_LOCALE_ZH_CN])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_CACHE_CHECK([whether mbsrtowcs works],
+ [gl_cv_func_mbsrtowcs_works],
+ [
+ dnl Initial guess, used when cross-compiling or when no suitable locale
+ dnl is present.
+changequote(,)dnl
+ case "$host_os" in
+ # Guess no on HP-UX and Solaris.
+ hpux* | solaris*) gl_cv_func_mbsrtowcs_works="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_func_mbsrtowcs_works="guessing yes" ;;
+ esac
+changequote([,])dnl
+ if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
+ AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+ /* Test whether the function works when started with a conversion state
+ in non-initial state. This fails on HP-UX 11.11 and Solaris 10. */
+ if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
+ {
+ const char input[] = "B\303\274\303\237er";
+ mbstate_t state;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
+ if (!mbsinit (&state))
+ {
+ const char *src = input + 2;
+ if (mbsrtowcs (NULL, &src, 10, &state) != 4)
+ return 1;
+ }
+ }
+ if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
+ {
+ const char input[] = "<\306\374\313\334\270\354>";
+ mbstate_t state;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ if (mbrtowc (NULL, input + 3, 1, &state) == (size_t)(-2))
+ if (!mbsinit (&state))
+ {
+ const char *src = input + 4;
+ if (mbsrtowcs (NULL, &src, 10, &state) != 3)
+ return 1;
+ }
+ }
+ if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
+ {
+ const char input[] = "B\250\271\201\060\211\070er";
+ mbstate_t state;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ if (mbrtowc (NULL, input + 1, 1, &state) == (size_t)(-2))
+ if (!mbsinit (&state))
+ {
+ const char *src = input + 2;
+ if (mbsrtowcs (NULL, &src, 10, &state) != 4)
+ return 1;
+ }
+ }
+ return 0;
+}],
+ [gl_cv_func_mbsrtowcs_works=yes],
+ [gl_cv_func_mbsrtowcs_works=no],
+ [])
+ fi
+ ])
+])
+
# Prerequisites of lib/mbsrtowcs.c.
AC_DEFUN([gl_PREREQ_MBSRTOWCS], [
:
diff --git a/modules/mbsrtowcs b/modules/mbsrtowcs
index 7df1dbb74e..0a5450a5e4 100644
--- a/modules/mbsrtowcs
+++ b/modules/mbsrtowcs
@@ -5,6 +5,9 @@ Files:
lib/mbsrtowcs.c
m4/mbsrtowcs.m4
m4/mbstate_t.m4
+m4/locale-fr.m4
+m4/locale-ja.m4
+m4/locale-zh.m4
Depends-on:
wchar