[Patch] Make add_item smarter
Pierre A. Humblet
pierre@phumblet.no-ip.org
Sun May 30 04:25:00 GMT 2004
2004-05-30 Pierre Humblet <pierre.humblet@ieee.org>
* path.cc (mount_info::add_item): Make sure native path has drive
or UNC form. Call normalize_xxx_path instead of [back]slashify.
Remove test for double slashes. Reorganize to always debug_print.
-------------- next part --------------
Index: path.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/path.cc,v
retrieving revision 1.313
diff -u -p -b -r1.313 path.cc
--- path.cc 28 May 2004 19:50:06 -0000 1.313
+++ path.cc 30 May 2004 04:06:43 -0000
@@ -2176,41 +2176,40 @@ mount_info::sort ()
int
mount_info::add_item (const char *native, const char *posix, unsigned mountflags, int reg_p)
{
+ char nativetmp[CYG_MAX_PATH];
+ char posixtmp[CYG_MAX_PATH];
+ char *tail;
+ int err[2];
+
/* Something's wrong if either path is NULL or empty, or if it's
not a UNC or absolute path. */
- if ((native == NULL) || (*native == 0) ||
- (posix == NULL) || (*posix == 0) ||
- !isabspath (native) || !isabspath (posix) ||
+ if (native == NULL || *native == 0 || !isabspath (native) ||
+ !(is_unc_share (native) || isdrive (native)))
+ err[0] = EINVAL;
+ else
+ err[0] = normalize_win32_path (native, nativetmp, &tail);
+
+ if (posix == NULL || *posix == 0 || !isabspath (posix) ||
is_unc_share (posix) || isdrive (posix))
+ err[1] = EINVAL;
+ else
+ err[1] = normalize_posix_path (posix, posixtmp, &tail);
+
+ debug_printf ("%s[%s], %s[%s], %p",
+ native, err[0]?"error":nativetmp, posix, err[1]?"error":posixtmp,
+ mountflags);
+
+ if (err[0] || err[1])
{
- set_errno (EINVAL);
+ set_errno (err[0]?:err[1]);
return -1;
}
/* Make sure both paths do not end in /. */
- char nativetmp[CYG_MAX_PATH];
- char posixtmp[CYG_MAX_PATH];
-
- backslashify (native, nativetmp, 0);
nofinalslash (nativetmp, nativetmp);
-
- slashify (posix, posixtmp, 0);
nofinalslash (posixtmp, posixtmp);
- debug_printf ("%s[%s], %s[%s], %p",
- native, nativetmp, posix, posixtmp, mountflags);
-
- /* Duplicate /'s in path are an error. */
- for (char *p = posixtmp + 1; *p; ++p)
- {
- if (p[-1] == '/' && p[0] == '/')
- {
- set_errno (EINVAL);
- return -1;
- }
- }
-
/* Write over an existing mount item with the same POSIX path if
it exists and is from the same registry area. */
int i;
More information about the Cygwin-patches
mailing list