diff --git a/compat/mingw.c b/compat/mingw.c index 4b4b958fb5..688c7f3a8f 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -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]); }