aboutsummaryrefslogtreecommitdiff
path: root/compat/mingw.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2016-01-12 08:57:22 +0100
committerJunio C Hamano <gitster@pobox.com>2016-01-12 10:39:40 -0800
commit2f36eed936f70105e80681aafac645ff34acc667 (patch)
tree5a226a4147e6f56a021d0492b713c39907a7b4da /compat/mingw.c
parent833e48259e23aea76f3765d28d1b2200332301f7 (diff)
downloadgit-2f36eed936f70105e80681aafac645ff34acc667.tar.gz
git-2f36eed936f70105e80681aafac645ff34acc667.tar.xz
Refactor skipping DOS drive prefixes
Junio noticed that there is an implicit assumption in pretty much all the code calling has_dos_drive_prefix(): it forces all of its callsites to hardcode the knowledge that the DOS drive prefix is always two bytes long. While this assumption is pretty safe, we can still make the code more readable and less error-prone by introducing a function that skips the DOS drive prefix safely. While at it, we change the has_dos_drive_prefix() return value: it now returns the number of bytes to be skipped if there is a DOS drive prefix. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/mingw.c')
-rw-r--r--compat/mingw.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index f74da235f..10a51c058 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1917,26 +1917,22 @@ pid_t waitpid(pid_t pid, int *status, int options)
int mingw_offset_1st_component(const char *path)
{
- int offset = 0;
- if (has_dos_drive_prefix(path))
- offset = 2;
+ char *pos = (char *)path;
/* unc paths */
- else if (is_dir_sep(path[0]) && is_dir_sep(path[1])) {
-
+ if (!skip_dos_drive_prefix(&pos) &&
+ is_dir_sep(pos[0]) && is_dir_sep(pos[1])) {
/* skip server name */
- char *pos = strpbrk(path + 2, "\\/");
+ pos = strpbrk(pos + 2, "\\/");
if (!pos)
return 0; /* Error: malformed unc path */
do {
pos++;
} while (*pos && !is_dir_sep(*pos));
-
- offset = pos - path;
}
- return offset + is_dir_sep(path[offset]);
+ return pos + is_dir_sep(*pos) - path;
}
int xutftowcsn(wchar_t *wcs, const char *utfs, size_t wcslen, int utflen)