From 58e7b141e1f80204b70d214b058cd1450a882260 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Tue, 13 Jul 2010 12:19:52 -0400 Subject: [PATCH] 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 Signed-off-by: Johannes Schindelin --- compat/mingw.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 39ce7b446d..71adbc497a 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1849,23 +1849,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]); } -- 2.11.4.GIT