[Patch] mapping root directory to SystemDrive / CurrentDrive
Pierre A. Humblet
pierre@phumblet.no-ip.org
Wed Aug 4 00:27:00 GMT 2004
Here is a patch.
Pierre
2004-08-04 Pierre Humblet <pierre.humblet@ieee.org>
* cygheap.h (cwdstuff::drive_length): New member.
(cwdstuff::get_drive): New method.
* path.cc (normalize_win32_path): Simplify by using cwdstuff::get_drive.
(mount_info::conv_to_win32_path): Use cwdstuff::get_drive as default for /.
(cwdstuff::set): Initialize drive_length.
-------------- next part --------------
Index: cygheap.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/cygheap.h,v
retrieving revision 1.85
diff -u -p -r1.85 cygheap.h
--- cygheap.h 28 May 2004 19:50:05 -0000 1.85
+++ cygheap.h 4 Aug 2004 00:08:31 -0000
@@ -216,9 +216,16 @@ struct cwdstuff
char *posix;
char *win32;
DWORD hash;
+ DWORD drive_length;
muto *cwd_lock;
char *get (char *, int = 1, int = 0, unsigned = CYG_MAX_PATH);
DWORD get_hash ();
+ DWORD get_drive (char * dst)
+ {
+ get_initial ();
+ memcpy (dst, win32, drive_length);
+ return drive_length;
+ }
void init ();
void fixup_after_exec (char *, char *, DWORD);
bool get_initial ();
Index: path.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/path.cc,v
retrieving revision 1.317
diff -u -p -r1.317 path.cc
--- path.cc 17 Jun 2004 13:34:24 -0000 1.317
+++ path.cc 4 Aug 2004 00:08:38 -0000
@@ -980,27 +980,15 @@ normalize_win32_path (const char *src, c
}
else if (strchr (src, ':') == NULL && *src != '/')
{
- if (!cygheap->cwd.get (dst, 0))
- return get_errno ();
if (beg_src_slash)
- {
- if (dst[1] == ':')
- dst[2] = '\0';
- else if (is_unc_share (dst))
- {
- char *p = strpbrk (dst + 2, "\\/");
- if (p && (p = strpbrk (p + 1, "\\/")))
- *p = '\0';
- }
- }
- if (strlen (dst) + 1 + strlen (src) >= CYG_MAX_PATH)
- {
- debug_printf ("ENAMETOOLONG = normalize_win32_path (%s)", src);
- return ENAMETOOLONG;
- }
- dst += strlen (dst);
- if (!beg_src_slash)
- *dst++ = '\\';
+ dst += cygheap->cwd.get_drive (dst);
+ else if (!cygheap->cwd.get (dst, 0))
+ return get_errno ();
+ else
+ {
+ dst += strlen (dst);
+ *dst++ = '\\';
+ }
}
while (*src)
@@ -1520,9 +1508,13 @@ mount_info::conv_to_win32_path (const ch
return err;
chroot_ok = true;
}
- else
- backslashify (src_path, dst, 0);
-
+ else
+ {
+ int offset = 0;
+ if (src_path[1] != '/')
+ offset = cygheap->cwd.get_drive (dst);
+ backslashify (src_path, dst + offset, 0);
+ }
out:
MALLOC_CHECK;
if (chroot_ok || cygheap->root.ischroot_native (dst))
@@ -3705,6 +3697,17 @@ cwdstuff::set (const char *win32_cwd, co
win32 = (char *) crealloc (win32, strlen (win32_cwd) + 1);
strcpy (win32, win32_cwd);
}
+ if (win32[1] == ':')
+ drive_length = 2;
+ else if (win32[1] == '\\')
+ {
+ char * ptr = strechr (win32 + 2, '\\');
+ if (*ptr)
+ ptr = strechr (ptr + 1, '\\');
+ drive_length = ptr - win32;
+ }
+ else
+ drive_length = 0;
if (!posix_cwd)
{
More information about the Cygwin-patches
mailing list