From: Eric Blake Date: Thu, 10 Sep 2009 03:34:32 +0000 (-0600) Subject: strndup: fix improper m4 caching X-Git-Tag: v0.1~5504 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=587f0edadfcadc708f6144de37a0653e81518484;p=gnulib.git strndup: fix improper m4 caching * m4/strndup.m4 (gl_FUNC_STRNDUP): Rework to avoid side effects inside AC_CACHE_CHECK. Use REPLACE_STRNDUP, not HAVE_STRNDUP. (gl_PREREQ_STRNDUP): Delete. * m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Update default. * modules/string (Makefile.am): Substitute it. * lib/string.in.h (strndup): Modernize prototype. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index b5b4494ca..a9664bc72 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2009-09-09 Eric Blake + strndup: fix improper m4 caching + * m4/strndup.m4 (gl_FUNC_STRNDUP): Rework to avoid side effects + inside AC_CACHE_CHECK. Use REPLACE_STRNDUP, not HAVE_STRNDUP. + (gl_PREREQ_STRNDUP): Delete. + * m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Update default. + * modules/string (Makefile.am): Substitute it. + * lib/string.in.h (strndup): Modernize prototype. + getcwd: port to mingw * m4/getcwd.m4 (gl_FUNC_GETCWD): Mingw directories are very different from the POSIX assumptions made throughout the getcwd diff --git a/lib/string.in.h b/lib/string.in.h index 89c23c7f4..04deb4295 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -203,11 +203,11 @@ extern char *strdup (char const *__s); /* Return a newly allocated copy of at most N bytes of STRING. */ #if @GNULIB_STRNDUP@ -# if ! @HAVE_STRNDUP@ +# if @REPLACE_STRNDUP@ # undef strndup # define strndup rpl_strndup # endif -# if ! @HAVE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@ +# if @REPLACE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@ extern char *strndup (char const *__string, size_t __n); # endif #elif defined GNULIB_POSIXCHECK diff --git a/m4/string_h.m4 b/m4/string_h.m4 index 3dbbfe166..edc5c6e82 100644 --- a/m4/string_h.m4 +++ b/m4/string_h.m4 @@ -5,7 +5,7 @@ # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 8 +# serial 9 # Written by Paul Eggert. @@ -74,7 +74,6 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], HAVE_STPNCPY=1; AC_SUBST([HAVE_STPNCPY]) HAVE_STRCHRNUL=1; AC_SUBST([HAVE_STRCHRNUL]) HAVE_DECL_STRDUP=1; AC_SUBST([HAVE_DECL_STRDUP]) - HAVE_STRNDUP=1; AC_SUBST([HAVE_STRNDUP]) HAVE_DECL_STRNDUP=1; AC_SUBST([HAVE_DECL_STRNDUP]) HAVE_DECL_STRNLEN=1; AC_SUBST([HAVE_DECL_STRNLEN]) HAVE_STRPBRK=1; AC_SUBST([HAVE_STRPBRK]) @@ -90,6 +89,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR]) REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR]) REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR]) + REPLACE_STRNDUP=0; AC_SUBST([REPLACE_STRNDUP]) REPLACE_STRSIGNAL=0; AC_SUBST([REPLACE_STRSIGNAL]) REPLACE_STRTOK_R=0; AC_SUBST([REPLACE_STRTOK_R]) UNDEFINE_STRTOK_R=0; AC_SUBST([UNDEFINE_STRTOK_R]) diff --git a/m4/strndup.m4 b/m4/strndup.m4 index 4fa7d5a7c..437e7f650 100644 --- a/m4/strndup.m4 +++ b/m4/strndup.m4 @@ -1,4 +1,4 @@ -# strndup.m4 serial 16 +# strndup.m4 serial 17 dnl Copyright (C) 2002-2003, 2005-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -9,17 +9,20 @@ AC_DEFUN([gl_FUNC_STRNDUP], dnl Persuade glibc to declare strndup(). AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) AC_CHECK_DECLS_ONCE([strndup]) + AC_CHECK_FUNCS_ONCE([strndup]) if test $ac_cv_have_decl_strndup = no; then HAVE_DECL_STRNDUP=0 fi - # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'. - AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup], - [AC_RUN_IFELSE([ - AC_LANG_PROGRAM([[#include - #include ]], [[ + if test $ac_cv_func_strndup = yes; then + # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'. + AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup_works], + [AC_RUN_IFELSE([ + AC_LANG_PROGRAM([[#include + #include ]], [[ #ifndef HAVE_DECL_STRNDUP extern char *strndup (const char *, size_t); #endif @@ -28,26 +31,19 @@ AC_DEFUN([gl_FUNC_STRNDUP], free (s); s = strndup ("shorter string", 13); return s[13] != '\0';]])], - [gl_cv_func_strndup=yes], - [gl_cv_func_strndup=no], - [AC_CHECK_FUNC([strndup], - [AC_EGREP_CPP([too risky], [ -#ifdef _AIX - too risky -#endif - ], - [gl_cv_func_strndup=no], - [gl_cv_func_strndup=yes])], - [gl_cv_func_strndup=no])])]) - if test $gl_cv_func_strndup = yes; then - AC_DEFINE([HAVE_STRNDUP], [1], - [Define if you have the strndup() function and it works.]) + [gl_cv_func_strndup_works=yes], + [gl_cv_func_strndup_works=no], + [case $host_os in + aix*) gl_cv_func_strndup_works="guessing no";; + *) gl_cv_func_strndup_works="guessing yes";; + esac])]) + case $gl_cv_func_strndup_works in + *no) + REPLACE_STRNDUP=1 + AC_LIBOBJ([strndup]) + ;; + esac else - HAVE_STRNDUP=0 AC_LIBOBJ([strndup]) - gl_PREREQ_STRNDUP fi ]) - -# Prerequisites of lib/strndup.c. -AC_DEFUN([gl_PREREQ_STRNDUP], [:]) diff --git a/modules/string b/modules/string index 9bafa7e90..7a6ed94cc 100644 --- a/modules/string +++ b/modules/string @@ -66,7 +66,6 @@ string.h: string.in.h -e 's|@''HAVE_STPNCPY''@|$(HAVE_STPNCPY)|g' \ -e 's|@''HAVE_STRCHRNUL''@|$(HAVE_STRCHRNUL)|g' \ -e 's|@''HAVE_DECL_STRDUP''@|$(HAVE_DECL_STRDUP)|g' \ - -e 's|@''HAVE_STRNDUP''@|$(HAVE_STRNDUP)|g' \ -e 's|@''HAVE_DECL_STRNDUP''@|$(HAVE_DECL_STRNDUP)|g' \ -e 's|@''HAVE_DECL_STRNLEN''@|$(HAVE_DECL_STRNLEN)|g' \ -e 's|@''HAVE_STRPBRK''@|$(HAVE_STRPBRK)|g' \ @@ -82,6 +81,7 @@ string.h: string.in.h -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \ -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \ -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \ + -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \ -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \ -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \ -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \