1 #include "../../git-compat-util.h"
3 int win32_has_dos_drive_prefix(const char *path
)
8 * Does it start with an ASCII letter (i.e. highest bit not set),
11 if (!(0x80 & (unsigned char)*path
))
12 return *path
&& path
[1] == ':' ? 2 : 0;
15 * While drive letters must be letters of the English alphabet, it is
16 * possible to assign virtually _any_ Unicode character via `subst` as
17 * a drive letter to "virtual drives". Even `1`, or `ä`. Or fun stuff
20 * subst ֍: %USERPROFILE%\Desktop
22 for (i
= 1; i
< 4 && (0x80 & (unsigned char)path
[i
]); i
++)
23 ; /* skip first UTF-8 character */
24 return path
[i
] == ':' ? i
+ 1 : 0;
27 int win32_skip_dos_drive_prefix(char **path
)
29 int ret
= has_dos_drive_prefix(*path
);
34 int win32_offset_1st_component(const char *path
)
36 char *pos
= (char *)path
;
39 if (!skip_dos_drive_prefix(&pos
) &&
40 is_dir_sep(pos
[0]) && is_dir_sep(pos
[1])) {
41 /* skip server name */
42 pos
= strpbrk(pos
+ 2, "\\/");
44 return 0; /* Error: malformed unc path */
48 } while (*pos
&& !is_dir_sep(*pos
));
51 return pos
+ is_dir_sep(*pos
) - path
;