changeset 13158:6c2a74cfe75b

mbsinit, mbrtowc, wcrtomb: Improve idioms.
author Bruno Haible <bruno@clisp.org>
date Mon, 05 Apr 2010 12:24:52 +0200
parents a68f7ded5f97
children b6a5437d4591
files ChangeLog m4/mbrtowc.m4 m4/mbsinit.m4 m4/mbsnrtowcs.m4 m4/mbsrtowcs.m4 m4/wcrtomb.m4 m4/wcsnrtombs.m4 m4/wcsrtombs.m4
diffstat 8 files changed, 139 insertions(+), 111 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2010-04-05  Bruno Haible  <bruno@clisp.org>
+
+	mbsinit, mbrtowc, wcrtomb: Improve idioms.
+	* m4/mbsinit.m4 (gl_FUNC_MBSINIT): When the function does not exist,
+	don't set REPLACE_MBSINIT to 1.
+	* m4/mbrtowc.m4 (gl_FUNC_MBRTOWC): When the function does not exist,
+	don't set REPLACE_MBRTOWC to 1.
+	* m4/mbsrtowcs.m4 (gl_FUNC_MBSRTOWCS): When the function does not
+	exist, don't set REPLACE_MBSRTOWCS to 1.
+	* m4/mbsnrtowcs.m4 (gl_FUNC_MBSNRTOWCS): When the function does not
+	exist, don't set REPLACE_MBSNRTOWCS to 1.
+	* m4/wcrtomb.m4 (gl_FUNC_WCRTOMB): When the function does not exist,
+	don't set REPLACE_WCRTOMB to 1.
+	* m4/wcsrtombs.m4 (gl_FUNC_WCSRTOMBS): When the function does not
+	exist, don't set REPLACE_WCSRTOMBS to 1.
+	* m4/wcsnrtombs.m4 (gl_FUNC_WCSNRTOMBS): When the function does not
+	exist, don't set REPLACE_WCSNRTOMBS to 1.
+
 2010-04-05  Bruno Haible  <bruno@clisp.org>
 
 	ldexpl: Improve idiom.
--- a/m4/mbrtowc.m4
+++ b/m4/mbrtowc.m4
@@ -1,4 +1,4 @@
-# mbrtowc.m4 serial 16
+# mbrtowc.m4 serial 17
 dnl Copyright (C) 2001-2002, 2004-2005, 2008-2010 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
@@ -11,38 +11,39 @@
 
   AC_REQUIRE([AC_TYPE_MBSTATE_T])
   gl_MBSTATE_T_BROKEN
-  if test $REPLACE_MBSTATE_T = 1; then
-    REPLACE_MBRTOWC=1
-  fi
+
   AC_CHECK_FUNCS_ONCE([mbrtowc])
   if test $ac_cv_func_mbrtowc = no; then
     HAVE_MBRTOWC=0
-  fi
-  if test $HAVE_MBRTOWC != 0 && test $REPLACE_MBRTOWC != 1; then
-    gl_MBRTOWC_NULL_ARG
-    gl_MBRTOWC_RETVAL
-    gl_MBRTOWC_NUL_RETVAL
-    case "$gl_cv_func_mbrtowc_null_arg" in
-      *yes) ;;
-      *) AC_DEFINE([MBRTOWC_NULL_ARG_BUG], [1],
-           [Define if the mbrtowc function has the NULL string argument bug.])
-         REPLACE_MBRTOWC=1
-         ;;
-    esac
-    case "$gl_cv_func_mbrtowc_retval" in
-      *yes) ;;
-      *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1],
-           [Define if the mbrtowc function returns a wrong return value.])
-         REPLACE_MBRTOWC=1
-         ;;
-    esac
-    case "$gl_cv_func_mbrtowc_nul_retval" in
-      *yes) ;;
-      *) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1],
-           [Define if the mbrtowc function does not return 0 for a NUL character.])
-         REPLACE_MBRTOWC=1
-         ;;
-    esac
+  else
+    if test $REPLACE_MBSTATE_T = 1; then
+      REPLACE_MBRTOWC=1
+    else
+      gl_MBRTOWC_NULL_ARG
+      gl_MBRTOWC_RETVAL
+      gl_MBRTOWC_NUL_RETVAL
+      case "$gl_cv_func_mbrtowc_null_arg" in
+        *yes) ;;
+        *) AC_DEFINE([MBRTOWC_NULL_ARG_BUG], [1],
+             [Define if the mbrtowc function has the NULL string argument bug.])
+           REPLACE_MBRTOWC=1
+           ;;
+      esac
+      case "$gl_cv_func_mbrtowc_retval" in
+        *yes) ;;
+        *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1],
+             [Define if the mbrtowc function returns a wrong return value.])
+           REPLACE_MBRTOWC=1
+           ;;
+      esac
+      case "$gl_cv_func_mbrtowc_nul_retval" in
+        *yes) ;;
+        *) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1],
+             [Define if the mbrtowc function does not return 0 for a NUL character.])
+           REPLACE_MBRTOWC=1
+           ;;
+      esac
+    fi
   fi
   if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then
     gl_REPLACE_WCHAR_H
--- a/m4/mbsinit.m4
+++ b/m4/mbsinit.m4
@@ -1,5 +1,5 @@
-# mbsinit.m4 serial 3
-dnl Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+# mbsinit.m4 serial 4
+dnl Copyright (C) 2008, 2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -10,12 +10,14 @@
 
   AC_REQUIRE([AC_TYPE_MBSTATE_T])
   gl_MBSTATE_T_BROKEN
-  if test $REPLACE_MBSTATE_T = 1; then
-    REPLACE_MBSINIT=1
-  fi
+
   AC_CHECK_FUNCS_ONCE([mbsinit])
   if test $ac_cv_func_mbsinit = no; then
     HAVE_MBSINIT=0
+  else
+    if test $REPLACE_MBSTATE_T = 1; then
+      REPLACE_MBSINIT=1
+    fi
   fi
   if test $HAVE_MBSINIT = 0 || test $REPLACE_MBSINIT = 1; then
     gl_REPLACE_WCHAR_H
--- a/m4/mbsnrtowcs.m4
+++ b/m4/mbsnrtowcs.m4
@@ -1,5 +1,5 @@
-# mbsnrtowcs.m4 serial 1
-dnl Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+# mbsnrtowcs.m4 serial 2
+dnl Copyright (C) 2008, 2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -13,12 +13,14 @@
 
   AC_REQUIRE([AC_TYPE_MBSTATE_T])
   gl_MBSTATE_T_BROKEN
-  if test $REPLACE_MBSTATE_T = 1; then
-    REPLACE_MBSNRTOWCS=1
-  fi
+
   AC_CHECK_FUNCS_ONCE([mbsnrtowcs])
   if test $ac_cv_func_mbsnrtowcs = no; then
     HAVE_MBSNRTOWCS=0
+  else
+    if test $REPLACE_MBSTATE_T = 1; then
+      REPLACE_MBSNRTOWCS=1
+    fi
   fi
   if test $HAVE_MBSNRTOWCS = 0 || test $REPLACE_MBSNRTOWCS = 1; then
     gl_REPLACE_WCHAR_H
--- a/m4/mbsrtowcs.m4
+++ b/m4/mbsrtowcs.m4
@@ -1,4 +1,4 @@
-# mbsrtowcs.m4 serial 5
+# mbsrtowcs.m4 serial 6
 dnl Copyright (C) 2008-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -10,19 +10,20 @@
 
   AC_REQUIRE([AC_TYPE_MBSTATE_T])
   gl_MBSTATE_T_BROKEN
-  if test $REPLACE_MBSTATE_T = 1; then
-    REPLACE_MBSRTOWCS=1
-  fi
+
   AC_CHECK_FUNCS_ONCE([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
+  else
+    if test $REPLACE_MBSTATE_T = 1; then
+      REPLACE_MBSRTOWCS=1
+    else
+      gl_MBSRTOWCS_WORKS
+      case "$gl_cv_func_mbsrtowcs_works" in
+        *yes) ;;
+        *) REPLACE_MBSRTOWCS=1 ;;
+      esac
+    fi
   fi
   if test $HAVE_MBSRTOWCS = 0 || test $REPLACE_MBSRTOWCS = 1; then
     gl_REPLACE_WCHAR_H
--- a/m4/wcrtomb.m4
+++ b/m4/wcrtomb.m4
@@ -1,4 +1,4 @@
-# wcrtomb.m4 serial 4
+# wcrtomb.m4 serial 5
 dnl Copyright (C) 2008-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -10,37 +10,37 @@
 
   AC_REQUIRE([AC_TYPE_MBSTATE_T])
   gl_MBSTATE_T_BROKEN
-  if test $REPLACE_MBSTATE_T = 1; then
-    REPLACE_WCRTOMB=1
-  fi
+
   AC_CHECK_FUNCS_ONCE([wcrtomb])
   if test $ac_cv_func_wcrtomb = no; then
     HAVE_WCRTOMB=0
-  fi
-  if test $HAVE_WCRTOMB != 0 && test $REPLACE_WCRTOMB != 1; then
-    dnl On AIX 4.3, OSF/1 5.1 and Solaris 10, wcrtomb (NULL, 0, NULL) sometimes
-    dnl returns 0 instead of 1.
-    AC_REQUIRE([AC_PROG_CC])
-    AC_REQUIRE([gt_LOCALE_FR])
-    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 wcrtomb return value is correct],
-      [gl_cv_func_wcrtomb_retval],
-      [
-        dnl Initial guess, used when cross-compiling or when no suitable locale
-        dnl is present.
+  else
+    if test $REPLACE_MBSTATE_T = 1; then
+      REPLACE_WCRTOMB=1
+    else
+      dnl On AIX 4.3, OSF/1 5.1 and Solaris 10, wcrtomb (NULL, 0, NULL) sometimes
+      dnl returns 0 instead of 1.
+      AC_REQUIRE([AC_PROG_CC])
+      AC_REQUIRE([gt_LOCALE_FR])
+      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 wcrtomb return value is correct],
+        [gl_cv_func_wcrtomb_retval],
+        [
+          dnl Initial guess, used when cross-compiling or when no suitable locale
+          dnl is present.
 changequote(,)dnl
-        case "$host_os" in
-                                   # Guess no on AIX 4, OSF/1 and Solaris.
-          aix4* | osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;;
-                                   # Guess yes otherwise.
-          *)                       gl_cv_func_wcrtomb_retval="guessing yes" ;;
-        esac
+          case "$host_os" in
+                                     # Guess no on AIX 4, OSF/1 and Solaris.
+            aix4* | osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;;
+                                     # Guess yes otherwise.
+            *)                       gl_cv_func_wcrtomb_retval="guessing yes" ;;
+          esac
 changequote([,])dnl
-        if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
-          AC_TRY_RUN([
+          if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
+            AC_TRY_RUN([
 #include <locale.h>
 #include <stdio.h>
 #include <string.h>
@@ -69,15 +69,16 @@
     }
   return 0;
 }],
-            [gl_cv_func_wcrtomb_retval=yes],
-            [gl_cv_func_wcrtomb_retval=no],
-            [:])
-        fi
-      ])
-    case "$gl_cv_func_wcrtomb_retval" in
-      *yes) ;;
-      *) REPLACE_WCRTOMB=1 ;;
-    esac
+              [gl_cv_func_wcrtomb_retval=yes],
+              [gl_cv_func_wcrtomb_retval=no],
+              [:])
+          fi
+        ])
+      case "$gl_cv_func_wcrtomb_retval" in
+        *yes) ;;
+        *) REPLACE_WCRTOMB=1 ;;
+      esac
+    fi
   fi
   if test $HAVE_WCRTOMB = 0 || test $REPLACE_WCRTOMB = 1; then
     gl_REPLACE_WCHAR_H
--- a/m4/wcsnrtombs.m4
+++ b/m4/wcsnrtombs.m4
@@ -1,4 +1,4 @@
-# wcsnrtombs.m4 serial 2
+# wcsnrtombs.m4 serial 3
 dnl Copyright (C) 2008-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -10,12 +10,14 @@
 
   AC_REQUIRE([AC_TYPE_MBSTATE_T])
   gl_MBSTATE_T_BROKEN
-  if test $REPLACE_MBSTATE_T = 1; then
-    REPLACE_WCSNRTOMBS=1
-  fi
+
   AC_CHECK_FUNCS_ONCE([wcsnrtombs])
   if test $ac_cv_func_wcsnrtombs = no; then
     HAVE_WCSNRTOMBS=0
+  else
+    if test $REPLACE_MBSTATE_T = 1; then
+      REPLACE_WCSNRTOMBS=1
+    fi
   fi
   if test $HAVE_WCSNRTOMBS = 0 || test $REPLACE_WCSNRTOMBS = 1; then
     gl_REPLACE_WCHAR_H
--- a/m4/wcsrtombs.m4
+++ b/m4/wcsrtombs.m4
@@ -1,4 +1,4 @@
-# wcsrtombs.m4 serial 4
+# wcsrtombs.m4 serial 5
 dnl Copyright (C) 2008-2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -10,28 +10,29 @@
 
   AC_REQUIRE([AC_TYPE_MBSTATE_T])
   gl_MBSTATE_T_BROKEN
-  if test $REPLACE_MBSTATE_T = 1; then
-    REPLACE_WCSRTOMBS=1
-  fi
+
   AC_CHECK_FUNCS_ONCE([wcsrtombs])
   if test $ac_cv_func_wcsrtombs = no; then
     HAVE_WCSRTOMBS=0
-  fi
-  if test $HAVE_WCSRTOMBS != 0 && test $REPLACE_WCSRTOMBS != 1; then
-    gl_WCSRTOMBS_TERMINATION
-    gl_WCSRTOMBS_NULL
-    case "$gl_cv_func_wcsrtombs_termination" in
-      *yes) ;;
-      *) AC_DEFINE([WCSRTOMBS_TERMINATION_BUG], [1],
-           [Define if the wcsrtombs function may set the source pointer to NULL without NUL-terminating the destination.])
-         REPLACE_WCSRTOMBS=1 ;;
-    esac
-    case "$gl_cv_func_wcsrtombs_null" in
-      *yes) ;;
-      *) AC_DEFINE([WCSRTOMBS_NULL_ARG_BUG], [1],
-           [Define if the wcsrtombs function has the NULL destination argument bug.])
-         REPLACE_WCSRTOMBS=1 ;;
-    esac
+  else
+    if test $REPLACE_MBSTATE_T = 1; then
+      REPLACE_WCSRTOMBS=1
+    else
+      gl_WCSRTOMBS_TERMINATION
+      gl_WCSRTOMBS_NULL
+      case "$gl_cv_func_wcsrtombs_termination" in
+        *yes) ;;
+        *) AC_DEFINE([WCSRTOMBS_TERMINATION_BUG], [1],
+             [Define if the wcsrtombs function may set the source pointer to NULL without NUL-terminating the destination.])
+           REPLACE_WCSRTOMBS=1 ;;
+      esac
+      case "$gl_cv_func_wcsrtombs_null" in
+        *yes) ;;
+        *) AC_DEFINE([WCSRTOMBS_NULL_ARG_BUG], [1],
+             [Define if the wcsrtombs function has the NULL destination argument bug.])
+           REPLACE_WCSRTOMBS=1 ;;
+      esac
+    fi
   fi
   if test $HAVE_WCSRTOMBS = 0 || test $REPLACE_WCSRTOMBS = 1; then
     gl_REPLACE_WCHAR_H