Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 17b901b

Browse files
sunshinecodscho
authored andcommitted
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent b45b33f commit 17b901b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

compat/mingw.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,25 +1989,26 @@ const char *get_windows_home_directory(void)
19891989

19901990
int mingw_offset_1st_component(const char *path)
19911991
{
1992+
int offset = 0;
19921993
if (has_dos_drive_prefix(path))
1993-
return 2 + is_dir_sep(path[2]);
1994+
offset = 2;
19941995

19951996
/* unc paths */
1996-
if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {
1997+
else if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {
19971998

19981999
/* skip server name */
19992000
char *pos = strpbrk(path + 2, "\\/");
20002001
if (!pos)
2001-
return 0;
2002+
return 0; /* Error: malformed unc path */
20022003

20032004
do {
20042005
pos++;
20052006
} while (*pos && !is_dir_sep(*pos));
20062007

2007-
return pos - path;
2008+
offset = pos - path;
20082009
}
20092010

2010-
return is_dir_sep(path[0]);
2011+
return offset + is_dir_sep(path[offset]);
20112012
}
20122013

20132014
int xutftowcsn(wchar_t *wcs, const char *utfs, size_t wcslen, int utflen)

0 commit comments

Comments
 (0)