summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <cgf@redhat.com>2003-02-14 05:21:51 +0000
committerChristopher Faylor <cgf@redhat.com>2003-02-14 05:21:51 +0000
commitdf77d25fd4dd035436ae98b9745fcac3ea24da34 (patch)
treece38bee09eb706852f3c73397e511670187ddd94
parente07f1ec5d50d3781167acad813023c327a98bfd8 (diff)
downloadgdb-df77d25fd4dd035436ae98b9745fcac3ea24da34.tar.gz
* 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.
-rw-r--r--winsup/cygwin/ChangeLog.branch14
-rw-r--r--winsup/cygwin/dtable.cc6
-rw-r--r--winsup/cygwin/fhandler.cc4
-rw-r--r--winsup/cygwin/path.cc40
-rw-r--r--winsup/cygwin/path.h5
5 files changed, 48 insertions, 21 deletions
diff --git a/winsup/cygwin/ChangeLog.branch b/winsup/cygwin/ChangeLog.branch
index d319f36efb1..165327de7e3 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 6a87469a637..1b21033fddb 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 4e706d4bf92..af489f13d9a 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 3ff8b458d63..51130e7c651 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 95ae845d352..dfaa67061f6 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];
};