changeset 8075:731d7d652c87

Make pwd and readlink work also when run with an unreadable parent dir on systems with openat support. * lib/getcwd.c (__getcwd) [HAVE_PARTLY_WORKING_GETCWD]: Use the system provided getcwd function, even when we have openat support. Reported by Dmitry V. Levin in <http://bugzilla.redhat.com/227168>.
author Jim Meyering <jim@meyering.net>
date Sat, 03 Feb 2007 00:23:57 +0000
parents 2700fc6b6734
children 662352a3327e
files ChangeLog lib/getcwd.c
diffstat 2 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-02-03  Jim Meyering  <jim@meyering.net>
+
+	Make pwd and readlink work also when run with an unreadable parent dir
+	on systems with openat support.
+	* lib/getcwd.c (__getcwd) [HAVE_PARTLY_WORKING_GETCWD]: Use the system
+	provided getcwd function, even when we have openat support.
+	Reported by Dmitry V. Levin in <http://bugzilla.redhat.com/227168>.
+
 2007-02-02  Bruno Haible  <bruno@clisp.org>
 
 	* lib/string_.h (memmem, mempcpy, memrchr, stpcpy, stpncpy, strchrnul,
--- a/lib/getcwd.c
+++ b/lib/getcwd.c
@@ -140,13 +140,18 @@
   size_t allocated = size;
   size_t used;
 
-#if HAVE_PARTLY_WORKING_GETCWD && !defined AT_FDCWD
+#if HAVE_PARTLY_WORKING_GETCWD
   /* The system getcwd works, except it sometimes fails when it
      shouldn't, setting errno to ERANGE, ENAMETOOLONG, or ENOENT.  If
      AT_FDCWD is not defined, the algorithm below is O(N**2) and this
      is much slower than the system getcwd (at least on GNU/Linux).
      So trust the system getcwd's results unless they look
-     suspicious.  */
+     suspicious.
+
+     Use the system getcwd even if we have openat support, since the
+     system getcwd works even when a parent is unreadable, while the
+     openat-based approach does not.  */
+
 # undef getcwd
   dir = getcwd (buf, size);
   if (dir || (errno != ERANGE && !is_ENAMETOOLONG (errno) && errno != ENOENT))