From 1f6297a30c109108ac3ae505a8f051a9dff5529e Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 12 May 2004 16:23:32 +0000 Subject: [PATCH] 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. --- lib/ChangeLog | 8 ++++++++ lib/save-cwd.c | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 5d6e80d094..c45e649587 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,11 @@ +2004-05-11 Jim Meyering + + 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 * obstack.c, obstack.h: Import changes from libc. diff --git a/lib/save-cwd.c b/lib/save-cwd.c index 6fb39f0aa0..17d077db89 100644 --- 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 @@ 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 -- 2.30.2