getcwd: Fix bug from 2011-08-17.
authorBruno Haible <bruno@clisp.org>
Sun, 27 Nov 2011 23:04:12 +0000 (00:04 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 27 Nov 2011 23:04:12 +0000 (00:04 +0100)
* m4/getcwd.m4 (gl_FUNC_GETCWD): Set REPLACE_GETCWD to 1 only on
platforms that need it.
* m4/getcwd-abort-bug.m4 (gl_FUNC_GETCWD_ABORT_BUG): Consider a return
code of 4 to be a failure, not a success. This ensures that
REPLACE_GETCWD becomes 1 on OpenBSD 4.9 and NetBSD 5.1.

ChangeLog
m4/getcwd-abort-bug.m4
m4/getcwd.m4

index ab3d043..d0efb2e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2011-11-27  Bruno Haible  <bruno@clisp.org>
 
+       getcwd: Fix bug from 2011-08-17.
+       * m4/getcwd.m4 (gl_FUNC_GETCWD): Set REPLACE_GETCWD to 1 only on
+       platforms that need it.
+       * m4/getcwd-abort-bug.m4 (gl_FUNC_GETCWD_ABORT_BUG): Consider a return
+       code of 4 to be a failure, not a success. This ensures that
+       REPLACE_GETCWD becomes 1 on OpenBSD 4.9 and NetBSD 5.1.
+
+2011-11-27  Bruno Haible  <bruno@clisp.org>
+
        binary-io tests: Avoid test failure on mingw when libtool is used.
        * tests/test-binary-io.c (main): Don't remove t-bin-out2.tmp here.
        Don't verify the size of t-bin-out1.tmp here.
index 60ea03c..057cc47 100644 (file)
@@ -1,4 +1,4 @@
-# serial 6
+# serial 7
 # Determine whether getcwd aborts when the length of the working directory
 # name is unusually large.  Any length between 4k and 16k trigger the bug
 # when using glibc-2.4.90-9 or older.
@@ -91,7 +91,8 @@ main ()
      results in a failed assertion.  */
   cwd = getcwd (NULL, 0);
   if (cwd == NULL)
-    fail = 4; /* getcwd failed.  This is ok, and expected.  */
+    fail = 4; /* getcwd failed: it refuses to return a string longer
+                 than PATH_MAX.  */
   free (cwd);
 
   /* Call rmdir first, in case the above chdir failed.  */
@@ -110,11 +111,18 @@ main ()
 }
           ]])],
     [gl_cv_func_getcwd_abort_bug=no],
-    dnl A "regular" nonzero return does not indicate this bug.
-    dnl An abort will provoke an exit code of something like 134 (128 + 6).
-    [test $? -gt 128 \
-      && gl_cv_func_getcwd_abort_bug=yes \
-      || gl_cv_func_getcwd_abort_bug=no],
+    [dnl An abort will provoke an exit code of something like 134 (128 + 6).
+     dnl An exit code of 4 can also occur (in OpenBSD 4.9, NetBSD 5.1 for
+     dnl example): getcwd (NULL, 0) fails rather than returning a string
+     dnl longer than PATH_MAX.  This may be POSIX compliant (in some
+     dnl interpretations of POSIX).  But gnulib's getcwd module wants to
+     dnl provide a non-NULL value in this case.
+     ret=$?
+     if test $ret -ge 128 || test $ret = 4; then
+       gl_cv_func_getcwd_abort_bug=yes
+     else
+       gl_cv_func_getcwd_abort_bug=no
+     fi],
     [gl_cv_func_getcwd_abort_bug=yes])
   ])
   AS_IF([test $gl_cv_func_getcwd_abort_bug = yes], [$1], [$2])
index dbdfcd2..8f3af32 100644 (file)
@@ -6,7 +6,7 @@
 # with or without modifications, as long as this notice is preserved.
 
 # Written by Paul Eggert.
-# serial 10
+# serial 11
 
 AC_DEFUN([gl_FUNC_GETCWD_NULL],
   [
@@ -139,12 +139,12 @@ AC_DEFUN([gl_FUNC_GETCWD],
       ;;
   esac
 
-  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;;
-  esac
+  if { case "$gl_cv_func_getcwd_null" in *yes) false;; *) true;; esac; } \
+     || test $gl_cv_func_getcwd_posix_signature != yes \
+     || test "$gl_cv_func_getcwd_path_max" != yes \
+     || test $gl_abort_bug = yes; then
+    REPLACE_GETCWD=1
+  fi
 ])
 
 # Prerequisites of lib/getcwd.c, when full replacement is in effect.