Work around wctob bug on Solaris 9.
authorBruno Haible <bruno@clisp.org>
Sun, 21 Dec 2008 00:22:07 +0000 (01:22 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 21 Dec 2008 00:22:07 +0000 (01:22 +0100)
ChangeLog
doc/posix-functions/wctob.texi
lib/wchar.in.h
m4/wchar.m4
m4/wctob.m4
modules/wchar
modules/wctob

index ad623c7..91792f1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2008-12-20  Bruno Haible  <bruno@clisp.org>
 
+       Work around wctob bug on Solaris <= 9.
+       * lib/wchar.in.h (wctob): Redefine if REPLACE_WCTOB is set.
+       * m4/wctob.m4 (gl_FUNC_WCTOB): Test whether wctob works.
+       * m4/wchar.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCTOB.
+       * modules/wchar (Makefile.am): Substitute REPLACE_WCTOB.
+       * modules/wctob (Files): Add m4/locale-fr.m4.
+       * doc/posix-functions/wctob.texi: Mention the Solaris bug.
+
+2008-12-20  Bruno Haible  <bruno@clisp.org>
+
        * doc/posix-functions/select.texi: Mention Solaris 2.6 bug with
        /dev/null.
        * tests/test-select-in.sh: Likewise.
index d610660..b6585f7 100644 (file)
@@ -12,6 +12,9 @@ Portability problems fixed by Gnulib:
 This function is missing on some platforms:
 HP-UX 11, IRIX 5.3, Solaris 2.6, mingw, Interix 3.5.
 @item
+This function does not work on some platforms:
+Solaris 9.
+@item
 This function is missing a declaration on some platforms:
 IRIX 6.5.
 @end itemize
index 2a8f839..e464733 100644 (file)
@@ -97,7 +97,11 @@ extern wint_t btowc (int c);
 
 /* Convert a wide character to a single-byte character.  */
 #if @GNULIB_WCTOB@
-# if !defined wctob && !@HAVE_DECL_WCTOB@
+# if @REPLACE_WCTOB@
+#  undef wctob
+#  define wctob rpl_wctob
+# endif
+# if (!defined wctob && !@HAVE_DECL_WCTOB@) || @REPLACE_WCTOB@
 /* wctob is provided by gnulib, or wctob exists but is not declared.  */
 extern int wctob (wint_t wc);
 # endif
index d7455f7..02e7f18 100644 (file)
@@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
 
 dnl Written by Eric Blake.
 
-# wchar.m4 serial 12
+# wchar.m4 serial 13
 
 AC_DEFUN([gl_WCHAR_H],
 [
@@ -76,6 +76,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
   HAVE_MBSRTOWCS=1;    AC_SUBST([HAVE_MBSRTOWCS])
   HAVE_DECL_WCTOB=1;   AC_SUBST([HAVE_DECL_WCTOB])
   HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH])
+  REPLACE_WCTOB=0;     AC_SUBST([REPLACE_WCTOB])
   REPLACE_WCWIDTH=0;   AC_SUBST([REPLACE_WCWIDTH])
   WCHAR_H='';          AC_SUBST([WCHAR_H])
 ])
index b9b8387..40cb709 100644 (file)
@@ -1,4 +1,4 @@
-# wctob.m4 serial 2
+# wctob.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,
@@ -15,8 +15,59 @@ AC_DEFUN([gl_FUNC_WCTOB],
     AC_LIBOBJ([wctob])
     gl_PREREQ_WCTOB
   else
-    dnl IRIX 6.5 has the wctob() function but does not declare it.
-    AC_CHECK_DECLS([wctob], [], [], [
+
+    dnl Solaris 9 has the wctob() function but it does not work.
+    AC_REQUIRE([AC_PROG_CC])
+    AC_REQUIRE([gt_LOCALE_FR])
+    AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+    AC_CACHE_CHECK([whether wctob works],
+      [gl_cv_func_wctob_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 Solaris <= 9.
+          solaris2.[1-9] | solaris2.[1-9].*)
+            gl_cv_func_wctob_works="guessing no" ;;
+            # Guess yes otherwise.
+          *) gl_cv_func_wctob_works="guessing yes" ;;
+        esac
+changequote([,])dnl
+        if test $LOCALE_FR != none; then
+          AC_TRY_RUN([
+#include <locale.h>
+#include <string.h>
+#include <wchar.h>
+int main ()
+{
+  if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
+    {
+      wchar_t wc;
+
+      if (mbtowc (&wc, "\374", 1) == 1)
+        if (wctob (wc) != (unsigned char) '\374')
+          return 1;
+    }
+  return 0;
+}],
+            [gl_cv_func_wctob_works=yes],
+            [gl_cv_func_wctob_works=no],
+            [])
+        fi
+      ])
+    case "$gl_cv_func_wctob_works" in
+      *yes) ;;
+      *) REPLACE_WCTOB=1 ;;
+    esac
+    if test $REPLACE_WCTOB = 1; then
+      gl_REPLACE_WCHAR_H
+      AC_LIBOBJ([wctob])
+      gl_PREREQ_WCTOB
+    else
+
+      dnl IRIX 6.5 has the wctob() function but does not declare it.
+      AC_CHECK_DECLS([wctob], [], [], [
 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
    <wchar.h>.
    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be included
@@ -26,9 +77,10 @@ AC_DEFUN([gl_FUNC_WCTOB],
 #include <time.h>
 #include <wchar.h>
 ])
-    if test $ac_cv_have_decl_wctob != yes; then
-      HAVE_DECL_WCTOB=0
-      gl_REPLACE_WCHAR_H
+      if test $ac_cv_have_decl_wctob != yes; then
+        HAVE_DECL_WCTOB=0
+        gl_REPLACE_WCHAR_H
+      fi
     fi
   fi
 ])
index e38a6da..f0bbe92 100644 (file)
@@ -40,6 +40,7 @@ wchar.h: wchar.in.h
              -e 's|@''HAVE_MBSRTOWCS''@|$(HAVE_MBSRTOWCS)|g' \
              -e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \
              -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \
+             -e 's|@''REPLACE_WCTOB''@|$(REPLACE_WCTOB)|g' \
              -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \
              -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
            < $(srcdir)/wchar.in.h; \
index d32cbcb..c4dc155 100644 (file)
@@ -4,6 +4,7 @@ wctob() function: convert wide character to unibyte character.
 Files:
 lib/wctob.c
 m4/wctob.m4
+m4/locale-fr.m4
 
 Depends-on:
 wchar