From b780e8dc0ca111f94e2c0fa0bc926fce87507b4b Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 5 Apr 2010 12:24:52 +0200 Subject: [PATCH] mbsinit, mbrtowc, wcrtomb: Improve idioms. --- ChangeLog | 18 ++++++++++++++ m4/mbrtowc.m4 | 61 +++++++++++++++++++++++----------------------- m4/mbsinit.m4 | 12 ++++++---- m4/mbsnrtowcs.m4 | 12 ++++++---- m4/mbsrtowcs.m4 | 23 +++++++++--------- m4/wcrtomb.m4 | 73 ++++++++++++++++++++++++++++---------------------------- m4/wcsnrtombs.m4 | 10 ++++---- m4/wcsrtombs.m4 | 41 +++++++++++++++---------------- 8 files changed, 139 insertions(+), 111 deletions(-) diff --git a/ChangeLog b/ChangeLog index cfd0859e8..fd9fb9951 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,23 @@ 2010-04-05 Bruno Haible + 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 + ldexpl: Improve idiom. * m4/ldexpl.m4 (gl_FUNC_LDEXPL): When the function is not declared, make sure to set HAVE_DECL_LDEXPL to 0. diff --git a/m4/mbrtowc.m4 b/m4/mbrtowc.m4 index 9ec93f561..606de5c9f 100644 --- 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_DEFUN([gl_FUNC_MBRTOWC], 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 diff --git a/m4/mbsinit.m4 b/m4/mbsinit.m4 index 13907a516..46c106fc4 100644 --- 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_DEFUN([gl_FUNC_MBSINIT], 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 diff --git a/m4/mbsnrtowcs.m4 b/m4/mbsnrtowcs.m4 index 6b10fb468..a9db326e4 100644 --- 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_DEFUN([gl_FUNC_MBSNRTOWCS], 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 diff --git a/m4/mbsrtowcs.m4 b/m4/mbsrtowcs.m4 index 846a29345..f9c430f01 100644 --- 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_DEFUN([gl_FUNC_MBSRTOWCS], 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 diff --git a/m4/wcrtomb.m4 b/m4/wcrtomb.m4 index 19c0c5fe9..6a2d772a3 100644 --- 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_DEFUN([gl_FUNC_WCRTOMB], 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 #include #include @@ -69,15 +69,16 @@ int main () } 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 diff --git a/m4/wcsnrtombs.m4 b/m4/wcsnrtombs.m4 index 4d432f661..d92e2ff8b 100644 --- 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_DEFUN([gl_FUNC_WCSNRTOMBS], 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 diff --git a/m4/wcsrtombs.m4 b/m4/wcsrtombs.m4 index e4f39a7dc..fb769f2d6 100644 --- 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_DEFUN([gl_FUNC_WCSRTOMBS], 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 -- 2.11.0