* path.h (path_conv::set_normalized_path): Add second argument and fill it in

throughout.
* path.cc (path_conv::check): Declare, set and use "strip_tail".
(path_conv::set_normalized_path): Add and use second argument, replacing all
tail stripping tests.
This commit is contained in:
Christopher Faylor 2004-12-23 21:37:44 +00:00
parent 7a2ba9dbec
commit 861ef99725
5 changed files with 34 additions and 22 deletions

View File

@ -1,3 +1,12 @@
2004-12-23 Pierre Humblet <pierre.humblet@ieee.org>
Christopher Faylor <cgf@timesys.com>
* path.h (path_conv::set_normalized_path): Add second argument and fill
it in throughout.
* path.cc (path_conv::check): Declare, set and use "strip_tail".
(path_conv::set_normalized_path): Add and use second argument,
replacing all tail stripping tests.
2004-12-23 Christopher Faylor <cgf@timesys.com> 2004-12-23 Christopher Faylor <cgf@timesys.com>
* cygthread.cc (cygthread::cygthread): Guard debugging variable with * cygthread.cc (cygthread::cygthread): Guard debugging variable with

View File

@ -357,9 +357,9 @@ build_fh_dev (const device& dev, const char *unix_name)
{ {
path_conv pc (dev); path_conv pc (dev);
if (unix_name) if (unix_name)
pc.set_normalized_path (unix_name); pc.set_normalized_path (unix_name, false);
else else
pc.set_normalized_path (dev.name); pc.set_normalized_path (dev.name, false);
return build_fh_pc (pc); return build_fh_pc (pc);
} }

View File

@ -41,7 +41,7 @@ inline fhandler_base&
fhandler_base::operator =(fhandler_base& x) fhandler_base::operator =(fhandler_base& x)
{ {
memcpy (this, &x, sizeof *this); memcpy (this, &x, sizeof *this);
pc.set_normalized_path (x.pc.normalized_path); pc.set_normalized_path (x.pc.normalized_path, false);
rabuf = NULL; rabuf = NULL;
ralen = 0; ralen = 0;
raixget = 0; raixget = 0;
@ -151,7 +151,7 @@ void
fhandler_base::set_name (path_conv &in_pc) fhandler_base::set_name (path_conv &in_pc)
{ {
memcpy (&pc, &in_pc, in_pc.size ()); memcpy (&pc, &in_pc, in_pc.size ());
pc.set_normalized_path (in_pc.normalized_path); pc.set_normalized_path (in_pc.normalized_path, false);
} }
/* Detect if we are sitting at EOF for conditions where Windows /* Detect if we are sitting at EOF for conditions where Windows

View File

@ -424,23 +424,22 @@ path_conv::fillin (HANDLE h)
} }
void void
path_conv::set_normalized_path (const char *path_copy) path_conv::set_normalized_path (const char *path_copy, bool strip_tail)
{ {
char *eopath = strchr (path, '\0'); char *p = strchr (path_copy, '\0');
size_t n;
if (dev.devn != FH_FS || !*path_copy || strncmp (path_copy, "//./", 4) == 0) if (strip_tail)
n = strlen (path_copy) + 1;
else
{ {
char *p = strchr (path_copy, '\0');
while (*--p == '.' || *p == ' ') while (*--p == '.' || *p == ' ')
continue; continue;
p[1] = '\0'; *++p = '\0';
n = 2 + p - path_copy;
} }
size_t n = 1 + p - path_copy;
normalized_path = path + sizeof (path) - n; normalized_path = path + sizeof (path) - n;
char *eopath = strchr (path, '\0');
if (normalized_path > eopath) if (normalized_path > eopath)
normalized_path_size = n; normalized_path_size = n;
else else
@ -804,6 +803,7 @@ path_conv::check (const char *src, unsigned opt,
add_ext_from_sym (sym); add_ext_from_sym (sym);
out: out:
bool strip_tail = false;
/* If the user wants a directory, do not return a symlink */ /* If the user wants a directory, do not return a symlink */
if (!need_directory || error) if (!need_directory || error)
/* nothing to do */; /* nothing to do */;
@ -836,7 +836,10 @@ out:
if (!tail) if (!tail)
/* nothing */; /* nothing */;
else if (tail[-1] != '\\') else if (tail[-1] != '\\')
*tail = '\0'; {
*tail = '\0';
strip_tail = true;
}
else else
{ {
error = ENOENT; error = ENOENT;
@ -901,7 +904,7 @@ out:
{ {
if (tail < path_end && tail > path_copy + 1) if (tail < path_end && tail > path_copy + 1)
*tail = '/'; *tail = '/';
set_normalized_path (path_copy); set_normalized_path (path_copy, strip_tail);
} }
#if 0 #if 0
@ -1838,12 +1841,12 @@ mount_info::add_reg_mount (const char *native_path, const char *posix_path, unsi
if (res != ERROR_SUCCESS) if (res != ERROR_SUCCESS)
goto err; goto err;
res = subkey.set_int ("flags", mountflags); res = subkey.set_int ("flags", mountflags);
if (mountflags & MOUNT_SYSTEM) if (mountflags & MOUNT_SYSTEM)
{ {
sys_mount_table_counter++; sys_mount_table_counter++;
cygwin_shared->sys_mount_table_counter++; cygwin_shared->sys_mount_table_counter++;
} }
return 0; /* Success */ return 0; /* Success */
} }
@ -1893,12 +1896,12 @@ mount_info::read_cygdrive_info_from_registry ()
if (i) if (i)
cygheap->user.reimpersonate (); cygheap->user.reimpersonate ();
if (r.get_string (CYGWIN_INFO_CYGDRIVE_PREFIX, cygdrive, sizeof (cygdrive), if (r.get_string (CYGWIN_INFO_CYGDRIVE_PREFIX, cygdrive, sizeof (cygdrive),
CYGWIN_INFO_CYGDRIVE_DEFAULT_PREFIX) != ERROR_SUCCESS && i == 0) CYGWIN_INFO_CYGDRIVE_DEFAULT_PREFIX) != ERROR_SUCCESS && i == 0)
continue; continue;
/* Fetch user cygdrive_flags from registry; returns MOUNT_CYGDRIVE on error. */ /* Fetch user cygdrive_flags from registry; returns MOUNT_CYGDRIVE on error. */
cygdrive_flags = r.get_int (CYGWIN_INFO_CYGDRIVE_FLAGS, cygdrive_flags = r.get_int (CYGWIN_INFO_CYGDRIVE_FLAGS,
MOUNT_CYGDRIVE | MOUNT_BINARY); MOUNT_CYGDRIVE | MOUNT_BINARY);
/* Sanitize */ /* Sanitize */
if (i == 0) if (i == 0)
@ -1931,7 +1934,7 @@ mount_info::write_cygdrive_info_to_registry (const char *cygdrive_prefix, unsign
/* Ensure that there is never a final slash */ /* Ensure that there is never a final slash */
nofinalslash (cygdrive_prefix, hold_cygdrive_prefix); nofinalslash (cygdrive_prefix, hold_cygdrive_prefix);
reg_key r (flags & MOUNT_SYSTEM, KEY_ALL_ACCESS, reg_key r (flags & MOUNT_SYSTEM, KEY_ALL_ACCESS,
CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, NULL); CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, NULL);
int res; int res;
res = r.set_string (CYGWIN_INFO_CYGDRIVE_PREFIX, hold_cygdrive_prefix); res = r.set_string (CYGWIN_INFO_CYGDRIVE_PREFIX, hold_cygdrive_prefix);
@ -1962,7 +1965,7 @@ mount_info::write_cygdrive_info_to_registry (const char *cygdrive_prefix, unsign
int int
mount_info::remove_cygdrive_info_from_registry (const char *cygdrive_prefix, unsigned flags) mount_info::remove_cygdrive_info_from_registry (const char *cygdrive_prefix, unsigned flags)
{ {
reg_key r (flags & MOUNT_SYSTEM, KEY_ALL_ACCESS, reg_key r (flags & MOUNT_SYSTEM, KEY_ALL_ACCESS,
CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME,
NULL); NULL);

View File

@ -214,7 +214,7 @@ class path_conv
unsigned __stdcall ndisk_links (DWORD); unsigned __stdcall ndisk_links (DWORD);
char *normalized_path; char *normalized_path;
size_t normalized_path_size; size_t normalized_path_size;
void set_normalized_path (const char *) __attribute__ ((regparm (2))); void set_normalized_path (const char *, bool) __attribute__ ((regparm (3)));
DWORD get_symlink_length () { return symlink_length; }; DWORD get_symlink_length () { return symlink_length; };
private: private:
DWORD symlink_length; DWORD symlink_length;