[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: new module 'mbsrtowcs'
From: |
Bruno Haible |
Subject: |
Re: new module 'mbsrtowcs' |
Date: |
Sun, 21 Dec 2008 13:36:06 +0100 |
User-agent: |
KMail/1.9.9 |
> New module 'mbsrtowcs'.
The libc function mbsrtowcs does not work on Solaris and HP-UX. This patch
works around it by using the gnulib replacement.
2008-12-21 Bruno Haible <address@hidden>
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.
*** doc/posix-functions/mbsrtowcs.texi.orig 2008-12-21 13:30:35.000000000
+0100
--- doc/posix-functions/mbsrtowcs.texi 2008-12-21 13:27:07.000000000 +0100
***************
*** 11,16 ****
--- 11,19 ----
@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:
*** m4/mbsrtowcs.m4.orig 2008-12-21 13:30:35.000000000 +0100
--- m4/mbsrtowcs.m4 2008-12-21 13:27:07.000000000 +0100
***************
*** 1,4 ****
! # mbsrtowcs.m4 serial 2
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,
--- 1,4 ----
! # 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,22 ****
--- 17,29 ----
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,29 ****
--- 31,119 ----
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], [
:
*** modules/mbsrtowcs.orig 2008-12-21 13:30:35.000000000 +0100
--- modules/mbsrtowcs 2008-12-21 13:27:07.000000000 +0100
***************
*** 5,10 ****
--- 5,13 ----
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