Start the 2.46 cycle
[git.git] / compat / win32 / path-utils.c
blobebf2f12eb666910eede5a7e04ee2ab5b0dddb0f8
1 #include "../../git-compat-util.h"
3 int win32_has_dos_drive_prefix(const char *path)
5 int i;
7 /*
8 * Does it start with an ASCII letter (i.e. highest bit not set),
9 * followed by a colon?
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
18 * like this:
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);
30 *path += ret;
31 return ret;
34 int win32_offset_1st_component(const char *path)
36 char *pos = (char *)path;
38 /* unc paths */
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, "\\/");
43 if (!pos)
44 return 0; /* Error: malformed unc path */
46 do {
47 pos++;
48 } while (*pos && !is_dir_sep(*pos));
51 return pos + is_dir_sep(*pos) - path;