From 47063f00e4eae2ed37096eda54429c025c0bc7b5 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Mon, 1 Oct 2001 04:10:07 +0000 Subject: Add "path.h" include throughout, where needed. Use new path_conv methods and operators to simplify testing for directory and attributes, throughout. * path.h (path_conv::exists): New method. (path_conv::has_attribute): Ditto. (path_conv::isdir): Ditto. (path_conv::DWORD &): New operator. (path_conv::int &): Ditto. * dir.cc (rmdir): Eliminate a goto. * dtable.cc (dtable::build_fhandler): Accept opt and suffix info for path_conv.check. Return fh == NULL on path_conv error. Pass unit to set_name as appropriate. (dtable::reset_unix_path_name): New method. * dtable.h (dtable): Declare new method. Reflect arg changes to build_fhandler. * fhandler.cc (fhandler_disk_dummy_name): Eliminate. (fhandler_base::set_name): Expect paths to be NULL. Build unix_path_name from win32_path_name when it is a device. (fhandler_base::reset_unix_path_name): New method. (fhandler_base::raw_read): Report EISDIR when ERROR_INVALID_FUNCTION or ERROR_INVALID_PARAMETER and reading a directory. (fhandler_disk_file::fstat): Don't call stat_dev since we should now never be calling fhandler_disk_file methods with devices. (fhandler_base::fhandler_base): Clear {unix,win32}_path_name. (fhandler_base::~fhandler_base): Always free {unix,win32}_path_name. (fhandler_disk_file::fhandler_disk_file): Remove set_no_free_names kludge. (fhandler_disk_file::open): Ditto. * fhandler.h (fhandler_base::no_free_names): Eliminate. (fhandler_base::set_no_free_names): Ditto. * fhandler_tty.cc (fhandler_tty_slave::fhandler_tty_slave): Don't set unix_path_name here. * path.cc (fchdir): Lock fd table throughout. Use new dtable::reset_unix_path_name method to reset path. * syscalls.cc (stat_worker): Reorganize to always call fstat method. Pass path_conv method to fhandler_*::open. (chroot): Elminate a goto. --- winsup/cygwin/path.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'winsup/cygwin/path.cc') diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 1c7c554af..2aa19e1aa 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -2428,8 +2428,7 @@ symlink (const char *topath, const char *frompath) syscall_printf ("symlink (%s, %s)", topath, win32_path.get_win32 ()); - if (win32_path.is_device () || - win32_path.file_attributes () != (DWORD) -1) + if (win32_path.is_device () || win32_path.exists ()) { set_errno (EEXIST); goto done; @@ -2897,7 +2896,7 @@ readlink (const char *path, char *buf, int buflen) return -1; } - if (pathbuf.file_attributes () == (DWORD) -1) + if (!pathbuf.exists ()) { set_errno (ENOENT); return -1; @@ -3106,8 +3105,9 @@ fchdir (int fd) set_errno (EBADF); return -1; } + SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fchdir"); int ret = chdir (cygheap->fdtab[fd]->get_name ()); - if (!ret) + if (ret == 0) { /* The name in the fhandler is explicitely overwritten with the full path. Otherwise fchmod() to a path originally given as a relative path could @@ -3119,13 +3119,11 @@ fchdir (int fd) The 2nd fchmod should chdir to the same dir as the first call, not to it's parent dir. */ - char path[MAX_PATH]; char posix_path[MAX_PATH]; - mount_table->conv_to_posix_path (cygheap->cwd.get (path, 0, 1), - posix_path, 0); - cygheap->fdtab[fd]->set_name (path, posix_path); + cygheap->fdtab.reset_unix_path_name (fd, cygheap->cwd.get (posix_path, 1, 1)); } + ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fchdir"); syscall_printf ("%d = fchdir (%d)", ret, fd); return ret; } -- cgit v1.2.3