diff --git a/compat/mingw.c b/compat/mingw.c index 385a9e766d..b509285d85 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1989,25 +1989,26 @@ const char *get_windows_home_directory(void) 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]); } int xutftowcsn(wchar_t *wcs, const char *utfs, size_t wcslen, int utflen)