X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fsave-cwd.c;h=5ad790a4d3542a7deafd4f5b9ac6325769e2b1da;hb=ef40bd4ace778faa7f6201a9a60a0300894e7f68;hp=596b78c8d9a56d1d5710a27349988998851b93ab;hpb=348925857a90662fb2bc8184f301ef16eff8ef80;p=gnulib.git diff --git a/lib/save-cwd.c b/lib/save-cwd.c index 596b78c8d..5ad790a4d 100644 --- a/lib/save-cwd.c +++ b/lib/save-cwd.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Written by Jim Meyering. */ @@ -33,17 +33,26 @@ # include #endif -#if HAVE_FCNTL_H -# include -#else -# include -#endif +#include #include #include "chdir-long.h" +#include "unistd-safer.h" #include "xgetcwd.h" +/* On systems without the fchdir function (WOE), pretend that open + always returns -1 so that save_cwd resorts to using xgetcwd. + Since chdir_long requires fchdir, use chdir instead. */ +#if !HAVE_FCHDIR +# undef open +# define open(File, Flags) (-1) +# undef fchdir +# define fchdir(Fd) (abort (), -1) +# undef chdir_long +# define chdir_long(Dir) chdir (Dir) +#endif + /* Record the location of the current working directory in CWD so that the program may change to other directories and later use restore_cwd to return to the recorded location. This function may allocate @@ -69,10 +78,10 @@ save_cwd (struct saved_cwd *cwd) { cwd->name = NULL; - cwd->desc = open (".", O_RDONLY); + cwd->desc = fd_safer (open (".", O_RDONLY)); if (cwd->desc < 0) { - cwd->desc = open (".", O_WRONLY); + cwd->desc = fd_safer (open (".", O_WRONLY)); if (cwd->desc < 0) { cwd->name = xgetcwd ();