Prior to this change, the save_cwd caller required read access to the
authorJim Meyering <jim@meyering.net>
Wed, 12 May 2004 16:23:32 +0000 (16:23 +0000)
committerJim Meyering <jim@meyering.net>
Wed, 12 May 2004 16:23:32 +0000 (16:23 +0000)
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.

lib/ChangeLog
lib/save-cwd.c

index 5d6e80d094f3a584783587b71dcaa20670a97084..c45e6495879315810dcdff1cd756f239451b69c9 100644 (file)
@@ -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.
index 6fb39f0aa0c91e3864951bf7087268766bda81d8..17d077db890d0b766d9d045f74c53d045c94b36d 100644 (file)
@@ -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 @@ save_cwd (struct saved_cwd *cwd)
 #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