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>
This commit is contained in:

committed by
Junio C Hamano

parent
833e48259e
commit
2f36eed936
@ -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)
|
||||
|
Reference in New Issue
Block a user