From ff938546975d416cf33466f54f80ec1b37e2693c Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Fri, 24 May 2002 05:44:10 +0000 Subject: [PATCH] * dtable.cc (dtable::build_fhandler_from_name): Just pass posix path along to set_name via return_and_clear_normalized_path. (dtable::build_fhandler): New method with const char * argument. (dtable::reset_unix_path_name): Eliminate. (dtable::dup_worker): Use correct build_fhandler method. * mmap.cc (mmap_record::alloc_fh): Ditto. * dtable.h (dtable::build_fhandler): New method. (dtable::reset_unix_path_name): Eliminate. * fhandler.cc (fhandler_base::set_name): Assume that unix_name has already been cmalloced. (fhandler_base::reset_unix_path_name): Eliminate. (fhandler_base::~fhandler_base): Coercion for cfree. * fhandler.h (fhandler_base::unix_path_name): Make const char *. (fhandler_base::win32_path_name): Ditto. (fhandler_base::reset_unix_path_name): Eliminate. * fhandler_disk_file.cc (fhandler_cygdrive::set_drives): Accommodate const char *ness of win32_path_name. * fhandler_socket.cc (fhandler_socket::fstat): Accommodate new set_name requirements. * path.cc (path_conv::return_and_clear_normalized_path): New method. (path_conv::clear_normalized_path): Eliminate. (path_conv::~path_conv): Ditto. (path_conv::check): Accommodate new build_fhandler method. * path.h (path_conv::~path_conv): Eliminate. (path_conv::clear_normalized_path): Ditto. (path_conv::return_and_clear_normalized_path): Declare new method. --- winsup/cygwin/ChangeLog | 29 +++++++++++++++++++++++++++++ winsup/cygwin/dtable.cc | 24 ++++++++++++------------ winsup/cygwin/dtable.h | 3 ++- winsup/cygwin/fhandler.cc | 27 ++++++++++++--------------- winsup/cygwin/fhandler.h | 8 +++----- winsup/cygwin/fhandler_disk_file.cc | 6 +++--- winsup/cygwin/fhandler_socket.cc | 2 +- winsup/cygwin/mmap.cc | 2 +- winsup/cygwin/path.cc | 21 ++++++--------------- winsup/cygwin/path.h | 3 +-- 10 files changed, 70 insertions(+), 55 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 512fe72d8..cd682cbe8 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,32 @@ +2002-05-24 Christopher Faylor + + * dtable.cc (dtable::build_fhandler_from_name): Just pass posix path + along to set_name via return_and_clear_normalized_path. + (dtable::build_fhandler): New method with const char * argument. + (dtable::reset_unix_path_name): Eliminate. + (dtable::dup_worker): Use correct build_fhandler method. + * mmap.cc (mmap_record::alloc_fh): Ditto. + * dtable.h (dtable::build_fhandler): New method. + (dtable::reset_unix_path_name): Eliminate. + * fhandler.cc (fhandler_base::set_name): Assume that unix_name has + already been cmalloced. + (fhandler_base::reset_unix_path_name): Eliminate. + (fhandler_base::~fhandler_base): Coercion for cfree. + * fhandler.h (fhandler_base::unix_path_name): Make const char *. + (fhandler_base::win32_path_name): Ditto. + (fhandler_base::reset_unix_path_name): Eliminate. + * fhandler_disk_file.cc (fhandler_cygdrive::set_drives): Accommodate + const char *ness of win32_path_name. + * fhandler_socket.cc (fhandler_socket::fstat): Accommodate new set_name + requirements. + * path.cc (path_conv::return_and_clear_normalized_path): New method. + (path_conv::clear_normalized_path): Eliminate. + (path_conv::~path_conv): Ditto. + (path_conv::check): Accommodate new build_fhandler method. + * path.h (path_conv::~path_conv): Eliminate. + (path_conv::clear_normalized_path): Ditto. + (path_conv::return_and_clear_normalized_path): Declare new method. + 2002-05-23 Christopher Faylor * path.cc (path_conv::check): Make sure any trailing path component is diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index e4f2ddfbc..3c91e50af 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -287,14 +287,22 @@ dtable::build_fhandler_from_name (int fd, const char *name, HANDLE handle, return NULL; } - fhandler_base *fh = build_fhandler (fd, pc.get_devn (), pc.normalized_path, pc, pc.get_unitn ()); - pc.clear_normalized_path (); + fhandler_base *fh = build_fhandler (fd, pc.get_devn (), + pc.return_and_clear_normalized_path (), + pc, pc.get_unitn ()); return fh; } +fhandler_base * +dtable::build_fhandler (int fd, DWORD dev, const char *unix_name, + const char *win32_name, int unit) +{ + return build_fhandler (fd, dev, cstrdup (unix_name), win32_name, unit); +} + #define cnew(name) new ((void *) ccalloc (HEAP_FHANDLER, 1, sizeof (name))) name fhandler_base * -dtable::build_fhandler (int fd, DWORD dev, const char *unix_name, +dtable::build_fhandler (int fd, DWORD dev, char *unix_name, const char *win32_name, int unit) { fhandler_base *fh; @@ -400,7 +408,7 @@ dtable::build_fhandler (int fd, DWORD dev, const char *unix_name, fhandler_base * dtable::dup_worker (fhandler_base *oldfh) { - fhandler_base *newfh = build_fhandler (-1, oldfh->get_device (), NULL); + fhandler_base *newfh = build_fhandler (-1, oldfh->get_device ()); *newfh = *oldfh; newfh->set_io_handle (NULL); if (oldfh->dup (newfh)) @@ -478,14 +486,6 @@ done: return res; } -void -dtable::reset_unix_path_name (int fd, const char *name) -{ - SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "reset_unix_name"); - fds[fd]->reset_unix_path_name (name); - ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "reset_unix_name"); -} - select_record * dtable::select_read (int fd, select_record *s) { diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h index 47e0a3b78..5a8f5697a 100644 --- a/winsup/cygwin/dtable.h +++ b/winsup/cygwin/dtable.h @@ -50,6 +50,8 @@ public: void fixup_after_fork (HANDLE); fhandler_base *build_fhandler (int fd, DWORD dev, const char *unix_name, const char *win32_name = NULL, int unit = -1); + fhandler_base *build_fhandler (int fd, DWORD dev, char *unix_name = NULL, + const char *win32_name = NULL, int unit = -1); fhandler_base *build_fhandler_from_name (int fd, const char *name, HANDLE h, path_conv& pc, unsigned opts = PC_SYM_FOLLOW, @@ -63,7 +65,6 @@ public: ReleaseResourceLock (LOCK_FD_LIST, READ_LOCK, "not open"); return res; } - void reset_unix_path_name (int fd, const char *name); int find_unused_handle (int start); int find_unused_handle () { return find_unused_handle (first_fd_for_open);} void release (int fd); diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index d1b0a4afc..ff334bfac 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -161,8 +161,9 @@ fhandler_base::set_name (const char *unix_path, const char *win32_path, int unit else { const char *fmt = get_native_name (); - win32_path_name = (char *) cmalloc (HEAP_STR, strlen(fmt) + 16); - __small_sprintf (win32_path_name, fmt, unit); + char *w = (char *) cmalloc (HEAP_STR, strlen(fmt) + 16); + __small_sprintf (w, fmt, unit); + win32_path_name = w; } if (win32_path_name == NULL) @@ -178,12 +179,15 @@ fhandler_base::set_name (const char *unix_path, const char *win32_path, int unit path_conv. Ideally, we should pass in a format string and build the unix_path, too. */ if (!is_device () || *win32_path_name != '\\') - unix_path_name = cstrdup (unix_path); + unix_path_name = unix_path; else { - unix_path_name = cstrdup (win32_path_name); - for (char *p = unix_path_name; (p = strchr (p, '\\')); p++) - *p = '/'; + char *p = cstrdup (win32_path_name); + unix_path_name = p; + while ((p = strchr (p, '\\')) != NULL) + *p++ = '/'; + if (unix_path) + cfree ((void *) unix_path); } if (unix_path_name == NULL) @@ -194,13 +198,6 @@ fhandler_base::set_name (const char *unix_path, const char *win32_path, int unit namehash = hash_path_name (0, win32_path_name); } -void -fhandler_base::reset_unix_path_name (const char *unix_path) -{ - cfree (unix_path_name); - unix_path_name = cstrdup (unix_path); -} - /* Detect if we are sitting at EOF for conditions where Windows returns an error but UNIX doesn't. */ static int __stdcall @@ -1047,9 +1044,9 @@ fhandler_base::fhandler_base (DWORD devtype, int unit): fhandler_base::~fhandler_base (void) { if (unix_path_name != NULL) - cfree (unix_path_name); + cfree ((void *) unix_path_name); if (win32_path_name != NULL) - cfree (win32_path_name); + cfree ((void *) win32_path_name); if (rabuf) free (rabuf); unix_path_name = win32_path_name = NULL; diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index a30364bce..740a29637 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -149,15 +149,13 @@ class fhandler_base size_t raixput; size_t rabuflen; - char *unix_path_name; - char *win32_path_name; + const char *unix_path_name; + const char *win32_path_name; DWORD open_status; public: - void set_name (const char * unix_path, const char * win32_path = NULL, - int unit = 0); + void set_name (const char * unix_path, const char *win32_path = NULL, int unit = 0); - void reset_unix_path_name (const char *); virtual fhandler_base& operator =(fhandler_base &x); fhandler_base (DWORD dev, int unit = 0); virtual ~fhandler_base (); diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 99f8b7ab0..347d1fd6d 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -775,10 +775,10 @@ void fhandler_cygdrive::set_drives () { const int len = 1 + 26 * DRVSZ; - win32_path_name = (char *) crealloc (win32_path_name, len); + char *p = (char *) crealloc ((void *) win32_path_name, len); - ndrives = GetLogicalDriveStrings (len, win32_path_name) / DRVSZ; - pdrive = win32_path_name; + win32_path_name = pdrive = p; + ndrives = GetLogicalDriveStrings (len, p) / DRVSZ; } int diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index e343c9021..e0e5c6363 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -248,7 +248,7 @@ int __stdcall fhandler_socket::fstat (struct __stat64 *buf, path_conv *pc) { fhandler_disk_file fh; - fh.set_name (get_name (), get_win32_name ()); + fh.set_name (cstrdup (get_name ()), get_win32_name ()); return fh.fstat (buf, pc); } diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc index c9db9980b..93afa856c 100644 --- a/winsup/cygwin/mmap.cc +++ b/winsup/cygwin/mmap.cc @@ -251,7 +251,7 @@ mmap_record::alloc_fh () the call to fork(). This requires creating a fhandler of the correct type to be sure to call the method of the correct class. */ - return cygheap->fdtab.build_fhandler (-1, get_device (), NULL); + return cygheap->fdtab.build_fhandler (-1, get_device ()); } void diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 9ae5df8c7..14c5d006d 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -366,20 +366,12 @@ fs_info::update (const char *win32_path) return true; } -void -path_conv::clear_normalized_path () +char * +path_conv::return_and_clear_normalized_path () { - // not thread safe - if (normalized_path) - { - cfree (normalized_path); - normalized_path = NULL; - } -} - -path_conv::~path_conv () -{ - clear_normalized_path (); + char *s = normalized_path; + normalized_path = NULL; + return s; } /* Convert an arbitrary path SRC to a pure Win32 path, suitable for @@ -520,7 +512,7 @@ path_conv::check (const char *src, unsigned opt, { /* FIXME: Calling build_fhandler here is not the right way to handle this. */ fhandler_virtual *fh = - (fhandler_virtual *) cygheap->fdtab.build_fhandler (-1, devn, path_copy, NULL, unit); + (fhandler_virtual *) cygheap->fdtab.build_fhandler (-1, devn, (const char *) path_copy, NULL, unit); int file_type = fh->exists (); switch (file_type) { @@ -731,7 +723,6 @@ out: *tail = '/'; normalized_path = cstrdup (path_copy); debug_printf ("path_copy %s", path_copy); - opt ^= PC_POSIX; } /* Deal with Windows stupidity which considers filename\. to be valid even when "filename" is not a directory. */ diff --git a/winsup/cygwin/path.h b/winsup/cygwin/path.h index 702461039..079bd5404 100644 --- a/winsup/cygwin/path.h +++ b/winsup/cygwin/path.h @@ -134,7 +134,6 @@ class path_conv unit (0), fileattr (INVALID_FILE_ATTRIBUTES), normalized_path (NULL) {path[0] = '\0';} - ~path_conv (); inline char *get_win32 () { return path; } operator char *() {return path;} operator const char *() {return path;} @@ -147,7 +146,7 @@ class path_conv DWORD get_drive_type () {return fs.drive_type;} BOOL fs_fast_ea () {return fs.sym_opt & PC_CHECK_EA;} void set_path (const char *p) {strcpy (path, p);} - void clear_normalized_path (); + char *return_and_clear_normalized_path (); }; /* Symlink marker */