X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fsave-cwd.c;h=f07973a3ab3fafe2df657c5c526c44922861a324;hb=7a97de48ca71de5fd6fac6d27f8d131d17e7fc9a;hp=596b78c8d9a56d1d5710a27349988998851b93ab;hpb=348925857a90662fb2bc8184f301ef16eff8ef80;p=gnulib.git diff --git a/lib/save-cwd.c b/lib/save-cwd.c index 596b78c8d..f07973a3a 100644 --- a/lib/save-cwd.c +++ b/lib/save-cwd.c @@ -1,7 +1,7 @@ /* save-cwd.c -- Save and restore current working directory. - Copyright (C) 1995, 1997, 1998, 2003, 2004, 2005 Free Software - Foundation, Inc. + Copyright (C) 1995, 1997, 1998, 2003, 2004, 2005, 2006 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 @@ -15,35 +15,36 @@ 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. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif +#include #include "save-cwd.h" +#include #include #include #include - -#if HAVE_UNISTD_H -# include -#endif - -#if HAVE_FCNTL_H -# include -#else -# include -#endif - -#include +#include #include "chdir-long.h" +#include "fcntl--.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 @@ -72,12 +73,8 @@ save_cwd (struct saved_cwd *cwd) cwd->desc = open (".", O_RDONLY); if (cwd->desc < 0) { - cwd->desc = open (".", O_WRONLY); - if (cwd->desc < 0) - { - cwd->name = xgetcwd (); - return cwd->name ? 0 : -1; - } + cwd->name = xgetcwd (); + return cwd->name ? 0 : -1; } return 0;