diff options
author | Christopher Faylor <me@cgf.cx> | 2003-02-14 05:21:51 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2003-02-14 05:21:51 +0000 |
commit | 9f4b815ca7048f8b5b867a64dac058ed6ec56a80 (patch) | |
tree | 8d5d85bc9ecf79d3a65809135a8a803e97fb3de4 /winsup | |
parent | 408a499886693356c4fe889dc4ef8dd0de52e54b (diff) | |
download | newlib-9f4b815ca7048f8b5b867a64dac058ed6ec56a80.zip newlib-9f4b815ca7048f8b5b867a64dac058ed6ec56a80.tar.gz newlib-9f4b815ca7048f8b5b867a64dac058ed6ec56a80.tar.bz2 |
* path.h (path_conv::set_normalized_path): Declare.
(path_conv::normalized_path_size): Declare.
(path_conv::return_and_clear_normalized_path): Delete declaration.
* path.cc (path_conv::set_normalized_path): Define. Puts normalized path in
path buf if there is room.
(path_conv::check): Call set_normalized_path.
(path_conv::return_and_clear_normalized_path): Delete definition.
* dtable.cc (build_fh_dev): Ditto.
* fhandler.cc (fhandler_base::operator =): Ditto.
(fhandler_base::~fhandler_base): Only free normalized_path when appropriate.
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/ChangeLog.branch | 14 | ||||
-rw-r--r-- | winsup/cygwin/dtable.cc | 6 | ||||
-rw-r--r-- | winsup/cygwin/fhandler.cc | 4 | ||||
-rw-r--r-- | winsup/cygwin/path.cc | 40 | ||||
-rw-r--r-- | winsup/cygwin/path.h | 5 |
5 files changed, 48 insertions, 21 deletions
diff --git a/winsup/cygwin/ChangeLog.branch b/winsup/cygwin/ChangeLog.branch index d319f36..165327d 100644 --- a/winsup/cygwin/ChangeLog.branch +++ b/winsup/cygwin/ChangeLog.branch @@ -1,3 +1,17 @@ +2003-02-14 Christopher Faylor <cgf@redhat.com> + + * path.h (path_conv::set_normalized_path): Declare. + (path_conv::normalized_path_size): Declare. + (path_conv::return_and_clear_normalized_path): Delete declaration. + * path.cc (path_conv::set_normalized_path): Define. Puts normalized + path in path buf if there is room. + (path_conv::check): Call set_normalized_path. + (path_conv::return_and_clear_normalized_path): Delete definition. + * dtable.cc (build_fh_dev): Ditto. + * fhandler.cc (fhandler_base::operator =): Ditto. + (fhandler_base::~fhandler_base): Only free normalized_path when + appropriate. + 2003-02-13 Christopher Faylor <cgf@redhat.com> Reorganize includes throughout so that path.h comes before fhandler.h. diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index 6a87469..1b21033 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -321,12 +321,12 @@ build_fh_dev (const device& dev, const char *unix_name) __small_sprintf (w32buf, dev.fmt, dev.minor); if (unix_name) - pc.normalized_path = cstrdup (unix_name); + pc.set_normalized_path (unix_name); else if (!dev.upper) - pc.normalized_path = cstrdup (dev.name); + pc.set_normalized_path (dev.name); else { - pc.normalized_path = cstrdup (w32buf); + pc.set_normalized_path (w32buf); for (char *p = strchr (pc.normalized_path, '\\'); p; p = strchr (p + 1, '\\')) diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 4e706d4..af489f1 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -38,7 +38,7 @@ inline fhandler_base& fhandler_base::operator =(fhandler_base &x) { memcpy (this, &x, sizeof *this); - pc.normalized_path = cstrdup (pc.normalized_path); + pc.set_normalized_path (pc.normalized_path); rabuf = NULL; ralen = 0; raixget = 0; @@ -1148,7 +1148,7 @@ fhandler_base::fhandler_base (): /* Normal I/O destructor */ fhandler_base::~fhandler_base (void) { - if (pc.normalized_path) + if (!pc.normalized_path_size && pc.normalized_path) cfree (pc.normalized_path); if (rabuf) free (rabuf); diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 3ff8b45..51130e7 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -392,14 +392,6 @@ fs_info::update (const char *win32_path) return true; } -char * -path_conv::return_and_clear_normalized_path () -{ - char *s = normalized_path; - normalized_path = NULL; - return s; -} - void path_conv::fillin (HANDLE h) { @@ -417,6 +409,23 @@ path_conv::fillin (HANDLE h) fs.drive_type = DRIVE_UNKNOWN; } +void +path_conv::set_normalized_path (const char *path_copy) +{ + char *eopath = strchr (path, '\0'); + size_t n = strlen (path_copy) + 1; + + normalized_path = path + sizeof (path) - n; + if (normalized_path > eopath) + normalized_path_size = n; + else + { + normalized_path = (char *) cmalloc (HEAP_STR, n); + normalized_path_size = 0; + } + memcpy (normalized_path, path_copy, n); +} + /* Convert an arbitrary path SRC to a pure Win32 path, suitable for passing to Win32 API routines. @@ -770,12 +779,6 @@ path_conv::check (const char *src, unsigned opt, add_ext_from_sym (sym); out: - if (opt & PC_POSIX) - { - if (tail[1] != '\0') - *tail = '/'; - normalized_path = cstrdup (path_copy); - } /* Deal with Windows stupidity which considers filename\. to be valid even when "filename" is not a directory. */ if (!need_directory || error) @@ -847,6 +850,15 @@ out: path_flags |= PATH_EXEC; } + if (!(opt & PC_POSIX)) + normalized_path_size = 0; + else + { + if (tail[1] != '\0') + *tail = '/'; + set_normalized_path (path_copy); + } + #if 0 if (!error) { diff --git a/winsup/cygwin/path.h b/winsup/cygwin/path.h index 95ae845..dfaa670 100644 --- a/winsup/cygwin/path.h +++ b/winsup/cygwin/path.h @@ -173,17 +173,18 @@ class path_conv DWORD 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);} - char *return_and_clear_normalized_path (); const char * root_dir () { return fs.root_dir; } DWORD volser () { return fs.serial; } const char *volname () {return fs.name; } void fillin (HANDLE h); inline size_t size () { - return (sizeof (*this) - sizeof (path)) + strlen (path) + 1; + return (sizeof (*this) - sizeof (path)) + strlen (path) + 1 + normalized_path_size; } char *normalized_path; + size_t normalized_path_size; + void set_normalized_path (const char *) __attribute__ ((regparm (2))); private: char path[MAX_PATH]; }; |