From 1a6fbdd7d28dff1868c5eb0baf0029b27e42526a Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Wed, 17 Aug 2011 16:14:12 -0600 Subject: [PATCH] getcwd-lgpl: fix m4 to match relaxed test for BSD Commit c6dc8f1 changed test-getcwd-lgpl to allow BSD behavior where getcwd(NULL,1) allocates the proper size, in addition to the glibc behavior of allocating exactly one byte then failing with ERANGE. But the m4 test was still rejecting the former behavior. However, merely fixing the test to avoid probing the behavior would be a regression of commit 8585ce2, since it was the only reason why rpl_getcwd was being compiled on mingw. Hence, we have to add a signature check in its place to keep mingw happy. * m4/getcwd.m4 (gl_FUNC_GETCWD_NULL): Relax probe. (gl_FUNC_GETCWD_SIGNATURE): New macro. (gl_FUNC_GETCWD_LGPL, gl_FUNC_GETCWD): Use it. * doc/posix-functions/getcwd.texi (getcwd): Tweak mentions of signature problem. Signed-off-by: Eric Blake --- ChangeLog | 7 +++++++ doc/posix-functions/getcwd.texi | 3 ++- m4/getcwd.m4 | 33 +++++++++++++++++++++++++-------- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7c8781f62..465a31f81 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2011-08-17 Eric Blake + getcwd-lgpl: fix m4 to match relaxed test for BSD + * m4/getcwd.m4 (gl_FUNC_GETCWD_NULL): Relax probe. + (gl_FUNC_GETCWD_SIGNATURE): New macro. + (gl_FUNC_GETCWD_LGPL, gl_FUNC_GETCWD): Use it. + * doc/posix-functions/getcwd.texi (getcwd): Tweak mentions of + signature problem. + getcwd: fix compilation on mingw64 * lib/unistd.in.h (includes) [mingw]: Include for getcwd. diff --git a/doc/posix-functions/getcwd.texi b/doc/posix-functions/getcwd.texi index ffb5086ff..8b471be67 100644 --- a/doc/posix-functions/getcwd.texi +++ b/doc/posix-functions/getcwd.texi @@ -14,7 +14,8 @@ On glibc platforms, @code{getcwd (NULL, n)} allocates memory for the result. On some other platforms, this call is not allowed. @item On some platforms, the prototype for @code{getcwd} uses @code{int} -instead of @code{size_t} for the size argument: +instead of @code{size_t} for the size argument when using non-standard +headers, and the declaration is missing from @code{}: mingw. @item On some platforms, @code{getcwd (buf, 0)} fails with @code{ERANGE} diff --git a/m4/getcwd.m4 b/m4/getcwd.m4 index 269fdd7c6..d3bbe597b 100644 --- a/m4/getcwd.m4 +++ b/m4/getcwd.m4 @@ -6,7 +6,7 @@ # with or without modifications, as long as this notice is preserved. # Written by Paul Eggert. -# serial 7 +# serial 8 AC_DEFUN([gl_FUNC_GETCWD_NULL], [ @@ -37,9 +37,6 @@ AC_DEFUN([gl_FUNC_GETCWD_NULL], return 0; } #endif - /* If size is non-zero, allocation must fail if size is too small */ - if (getcwd (NULL, 1)) - return 5; ]])], [gl_cv_func_getcwd_null=yes], [gl_cv_func_getcwd_null=no], @@ -55,6 +52,24 @@ AC_DEFUN([gl_FUNC_GETCWD_NULL], ]])]) ]) +AC_DEFUN([gl_FUNC_GETCWD_SIGNATURE], +[ + AC_CACHE_CHECK([for getcwd with POSIX signature], + [gl_cv_func_getcwd_posix_signature], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include ]], + [[extern + #ifdef __cplusplus + "C" + #endif + char *getcwd (char *, size_t); + ]]) + ], + [gl_cv_func_getcwd_posix_signature=yes], + [gl_cv_func_getcwd_posix_signature=no]) + ]) +]) dnl Guarantee that getcwd will malloc with a NULL first argument. Assumes dnl that either the system getcwd is robust, or that calling code is okay @@ -67,9 +82,10 @@ AC_DEFUN([gl_FUNC_GETCWD_LGPL], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) AC_REQUIRE([gl_FUNC_GETCWD_NULL]) + AC_REQUIRE([gl_FUNC_GETCWD_SIGNATURE]) - case $gl_cv_func_getcwd_null in - *yes) ;; + case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_posix_signature in + *yes,yes) ;; *) dnl Minimal replacement lib/getcwd-lgpl.c. REPLACE_GETCWD=1 @@ -83,6 +99,7 @@ AC_DEFUN([gl_FUNC_GETCWD], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) AC_REQUIRE([gl_FUNC_GETCWD_NULL]) + AC_REQUIRE([gl_FUNC_GETCWD_SIGNATURE]) AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles gl_abort_bug=no @@ -94,8 +111,8 @@ AC_DEFUN([gl_FUNC_GETCWD], gl_FUNC_GETCWD_ABORT_BUG([gl_abort_bug=yes]);; esac - case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_path_max,$gl_abort_bug in - *yes,yes,no) ;; + case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_posix_signature$gl_cv_func_getcwd_path_max,$gl_abort_bug in + *yes,yes,yes,no) ;; *) dnl Full replacement lib/getcwd.c, overrides LGPL replacement. REPLACE_GETCWD=1;; -- 2.11.0