Make mingw_offset_1st_component() behave consistently for all paths.

mingw_offset_1st_component() returns "foo" for inputs "/foo" and
"c:/foo", but inconsistently returns "/foo" for UNC input
"/machine/share/foo".  Fix it to return "foo" for all cases.

Reference: http://groups.google.com/group/msysgit/browse_thread/thread/c0af578549b5dda0

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Eric Sunshine
2010-07-13 12:19:52 -04:00
committed by Pat Thoyts
parent 6df8bcd8ab
commit 504c26dab5

View File

@@ -1818,23 +1818,24 @@ const char *get_windows_home_directory()
int mingw_offset_1st_component(const char *path)
{
int offset = 0;
if (has_dos_drive_prefix(path))
return 2 + is_dir_sep(path[2]);
offset = 2;
/* unc paths */
if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {
else if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {
/* skip server name */
char *pos = strpbrk(path + 2, "\\/");
if (!pos)
return 0;
return 0; /* Error: malformed unc path */
do {
pos++;
} while (*pos && !is_dir_sep(*pos));
return pos - path;
offset = pos - path;
}
return is_dir_sep(path[0]);
return offset + is_dir_sep(path[offset]);
}