changeset 5058:d67c037bd2ab

Prior to this change, the save_cwd caller required read access to the current directory on most systems (ones with the fchdir function). * save-cwd.c (save_cwd) [HAVE_FCHDIR]: If opening `.' read-only fails, try write-only, and finally, resort to using xgetcwd.
author Jim Meyering <jim@meyering.net>
date Wed, 12 May 2004 16:23:32 +0000
parents f4b3a4229349
children eb3efcec6ae2
files lib/ChangeLog lib/save-cwd.c
diffstat 2 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,11 @@
+2004-05-11  Jim Meyering  <jim@meyering.net>
+
+	Prior to this change, the save_cwd caller required read access to the
+	current directory on most systems (ones with the fchdir function).
+
+	* save-cwd.c (save_cwd) [HAVE_FCHDIR]: If opening `.' read-only
+	fails, try write-only, and finally, resort to using xgetcwd.
+
 2004-05-06  Paul Eggert  <eggert@cs.ucla.edu>
 
 	* obstack.c, obstack.h: Import changes from libc.
--- a/lib/save-cwd.c
+++ b/lib/save-cwd.c
@@ -1,5 +1,5 @@
 /* save-cwd.c -- Save and restore current working directory.
-   Copyright (C) 1995, 1997, 1998, 2003 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1997, 1998, 2003, 2004 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -76,7 +76,12 @@
 #if HAVE_FCHDIR
       cwd->desc = open (".", O_RDONLY | O_DIRECTORY);
       if (cwd->desc < 0)
-	return 1;
+	cwd->desc = open (".", O_WRONLY | O_DIRECTORY);
+      if (cwd->desc < 0)
+	{
+	  cwd->name = xgetcwd ();
+	  return cwd->name == NULL;
+	}
 
 # if __sun__ || sun
       /* On SunOS 4 and IRIX 5.3, fchdir returns EINVAL when auditing