diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2018-10-20 20:25:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-20 20:25:51 +0100 |
commit | 7c791f3dfcc00b892bcea9a1df63b36737d6eb1a (patch) | |
tree | 7839882f029e854f7fb9b3a25f1e35614998765d /src/win32/w32_util.c | |
parent | 6cc14ae3a76586722526eb6cca784b4386bfb2a1 (diff) | |
parent | a34f5b0db55ba2bd0080ccd8f08db157a76168a9 (diff) | |
download | libgit2-7c791f3dfcc00b892bcea9a1df63b36737d6eb1a.tar.gz |
Merge pull request #4852 from libgit2/ethomson/unc_paths
Win32 path canonicalization refactoring
Diffstat (limited to 'src/win32/w32_util.c')
-rw-r--r-- | src/win32/w32_util.c | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/src/win32/w32_util.c b/src/win32/w32_util.c index b7b1ffa10..5996c9fb9 100644 --- a/src/win32/w32_util.c +++ b/src/win32/w32_util.c @@ -93,71 +93,3 @@ int git_win32__hidden(bool *out, const char *path) *out = (attrs & FILE_ATTRIBUTE_HIDDEN) ? true : false; return 0; } - -/** - * Removes any trailing backslashes from a path, except in the case of a drive - * letter path (C:\, D:\, etc.). This function cannot fail. - * - * @param path The path which should be trimmed. - * @return The length of the modified string (<= the input length) - */ -size_t git_win32__path_trim_end(wchar_t *str, size_t len) -{ - while (1) { - if (!len || str[len - 1] != L'\\') - break; - - /* Don't trim backslashes from drive letter paths, which - * are 3 characters long and of the form C:\, D:\, etc. */ - if (len == 3 && git_win32__isalpha(str[0]) && str[1] == ':') - break; - - len--; - } - - str[len] = L'\0'; - - return len; -} - -/** - * Removes any of the following namespace prefixes from a path, - * if found: "\??\", "\\?\", "\\?\UNC\". This function cannot fail. - * - * @param path The path which should be converted. - * @return The length of the modified string (<= the input length) - */ -size_t git_win32__canonicalize_path(wchar_t *str, size_t len) -{ - static const wchar_t dosdevices_prefix[] = L"\\\?\?\\"; - static const wchar_t nt_prefix[] = L"\\\\?\\"; - static const wchar_t unc_prefix[] = L"UNC\\"; - size_t to_advance = 0; - - /* "\??\" -- DOS Devices prefix */ - if (len >= CONST_STRLEN(dosdevices_prefix) && - !wcsncmp(str, dosdevices_prefix, CONST_STRLEN(dosdevices_prefix))) { - to_advance += CONST_STRLEN(dosdevices_prefix); - len -= CONST_STRLEN(dosdevices_prefix); - } - /* "\\?\" -- NT namespace prefix */ - else if (len >= CONST_STRLEN(nt_prefix) && - !wcsncmp(str, nt_prefix, CONST_STRLEN(nt_prefix))) { - to_advance += CONST_STRLEN(nt_prefix); - len -= CONST_STRLEN(nt_prefix); - } - - /* "\??\UNC\", "\\?\UNC\" -- UNC prefix */ - if (to_advance && len >= CONST_STRLEN(unc_prefix) && - !wcsncmp(str + to_advance, unc_prefix, CONST_STRLEN(unc_prefix))) { - to_advance += CONST_STRLEN(unc_prefix); - len -= CONST_STRLEN(unc_prefix); - } - - if (to_advance) { - memmove(str, str + to_advance, len * sizeof(wchar_t)); - str[len] = L'\0'; - } - - return git_win32__path_trim_end(str, len); -} |