getcwd: don't fail in a deep directory on a system without openat
authorJim Meyering <meyering@redhat.com>
Mon, 19 Sep 2011 07:48:35 +0000 (09:48 +0200)
committerJim Meyering <meyering@redhat.com>
Mon, 19 Sep 2011 14:42:10 +0000 (16:42 +0200)
Before this change, getcwd would fail when called from a directory
of depth PATH_MAX / 3 or greater.  That was due to the fact that
the non-openat implementation used "..", "../..", "../../..", etc.
to access ancestor directories.  With too many, that string would
be longer than PATH_MAX.
* lib/getcwd.c (HAVE_OPENAT_SUPPORT): Define also when we are
using gnulib's openat replacement.
* m4/openat.m4: Set GNULIB_OPENAT, so getcwd.c knows when
we're using the replacement function.

ChangeLog
lib/getcwd.c
m4/openat.m4

index ff1985b..50a43e8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2011-09-19  Jim Meyering  <meyering@redhat.com>
+
+       getcwd: don't fail in a deep directory on a system without openat
+       Before this change, getcwd would fail when called from a directory
+       of depth PATH_MAX / 3 or greater.  That was due to the fact that
+       the non-openat implementation used "..", "../..", "../../..", etc.
+       to access ancestor directories.  With too many, that string would
+       be longer than PATH_MAX.
+       * lib/getcwd.c (HAVE_OPENAT_SUPPORT): Define also when we are
+       using gnulib's openat replacement.
+       * m4/openat.m4: Set GNULIB_OPENAT, so getcwd.c knows when
+       we're using the replacement function.
+
 2011-09-14  Martin von Gagern  <Martin.vGagern@gmx.net>
 
        maint.mk: avoid warnings from perl about missing files
index cf15521..f810161 100644 (file)
 
 #include <fcntl.h> /* For AT_FDCWD on Solaris 9.  */
 
-/* If this host provides the openat function, then enable
-   code below to make getcwd more efficient and robust.  */
-#ifdef HAVE_OPENAT
+/* If this host provides the openat function or if we're using the
+   gnulib replacement function, then enable code below to make getcwd
+   more efficient and robust.  */
+#if defined HAVE_OPENAT || defined GNULIB_OPENAT
 # define HAVE_OPENAT_SUPPORT 1
 #else
 # define HAVE_OPENAT_SUPPORT 0
index 43da4f2..05a6bd3 100644 (file)
@@ -51,6 +51,9 @@ AC_DEFUN([gl_FUNC_OPENAT],
   fi
   gl_FUNC_FCHOWNAT
   gl_FUNC_FSTATAT
+
+  dnl This is tested at least via getcwd.c.
+  gl_MODULE_INDICATOR([openat])
 ])
 
 # gl_FUNC_FCHOWNAT_DEREF_BUG([ACTION-IF-BUGGY[, ACTION-IF-NOT_BUGGY]])