Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/compat/win32/path-utils.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / compat / win32 / path-utils.c` 92 lines · 1930 bytes Raw Blame History 1 #define USE_THE_REPOSITORY_VARIABLE 2 3 #include "../../git-compat-util.h" 4 #include "../../environment.h" 5 #include "../../repository.h" 6 7 int win32_has_dos_drive_prefix(const char *path) 8 { 9 int i; 10 11 /* 12 * Does it start with an ASCII letter (i.e. highest bit not set), 13 * followed by a colon? 14 */ 15 if (!(0x80 & (unsigned char)*path)) 16 return *path && path[1] == ':' ? 2 : 0; 17 18 /* 19 * While drive letters must be letters of the English alphabet, it is 20 * possible to assign virtually _any_ Unicode character via `subst` as 21 * a drive letter to "virtual drives". Even `1`, or `ä`. Or fun stuff 22 * like this: 23 * 24 * subst ֍: %USERPROFILE%\Desktop 25 */ 26 for (i = 1; i < 4 && (0x80 & (unsigned char)path[i]); i++) 27 ; /* skip first UTF-8 character */ 28 return path[i] == ':' ? i + 1 : 0; 29 } 30 31 int win32_skip_dos_drive_prefix(char **path) 32 { 33 int ret = has_dos_drive_prefix(*path); 34 *path += ret; 35 return ret; 36 } 37 38 int win32_offset_1st_component(const char *path) 39 { 40 char *pos = (char *)path; 41 42 /* unc paths */ 43 if (!skip_dos_drive_prefix(&pos) && 44 is_dir_sep(pos[0]) && is_dir_sep(pos[1])) { 45 /* skip server name */ 46 pos = strpbrk(pos + 2, "\\/"); 47 if (!pos) 48 return 0; /* Error: malformed unc path */ 49 50 do { 51 pos++; 52 } while (*pos && !is_dir_sep(*pos)); 53 } 54 55 return pos + is_dir_sep(*pos) - path; 56 } 57 58 int win32_fspathncmp(const char *a, const char *b, size_t count) 59 { 60 int diff; 61 62 for (;;) { 63 if (!count--) 64 return 0; 65 if (!*a) 66 return *b ? -1 : 0; 67 if (!*b) 68 return +1; 69 70 if (is_dir_sep(*a)) { 71 if (!is_dir_sep(*b)) 72 return -1; 73 a++; 74 b++; 75 continue; 76 } else if (is_dir_sep(*b)) 77 return +1; 78 79 diff = repo_ignore_case(the_repository) ? 80 (unsigned char)tolower(*a) - (int)(unsigned char)tolower(*b) : 81 (unsigned char)*a - (int)(unsigned char)*b; 82 if (diff) 83 return diff; 84 a++; 85 b++; 86 } 87 } 88 89 int win32_fspathcmp(const char *a, const char *b) 90 { 91 return win32_fspathncmp(a, b, (size_t)-1); 92 }