Commit e54cf1a3 by Patrick Steinhardt

path: expose `git_path_is_absolute`

This function has previously been implemented in Windows-specific path
handling code as `path__is_absolute`. As we will need this functionality
in other parts, extract the logic into "path.h" alongside with a
non-Windows implementation.
parent 38e769cb
......@@ -105,6 +105,9 @@ GIT_INLINE(int) git_path_is_dot_or_dotdotW(const wchar_t *name)
(name[1] == L'.' && name[2] == L'\0')));
}
#define git_path_is_absolute(p) \
(git__isalpha((p)[0]) && (p)[1] == ':' && ((p)[2] == '\\' || (p)[2] == '/'))
/**
* Convert backslashes in path to forward slashes.
*/
......@@ -119,6 +122,10 @@ GIT_INLINE(void) git_path_mkposix(char *path)
}
#else
# define git_path_mkposix(p) /* blank */
#define git_path_is_absolute(p) \
((p)[0] == '/')
#endif
/**
......
......@@ -20,9 +20,6 @@
#define path__is_dirsep(p) ((p) == '/' || (p) == '\\')
#define path__is_absolute(p) \
(git__isalpha((p)[0]) && (p)[1] == ':' && ((p)[2] == '\\' || (p)[2] == '/'))
#define path__is_nt_namespace(p) \
(((p)[0] == '\\' && (p)[1] == '\\' && (p)[2] == '?' && (p)[3] == '\\') || \
((p)[0] == '/' && (p)[1] == '/' && (p)[2] == '?' && (p)[3] == '/'))
......@@ -73,9 +70,9 @@ static wchar_t *path__skip_prefix(wchar_t *path)
if (wcsncmp(path, L"UNC\\", 4) == 0)
path = path__skip_server(path + 4);
else if (path__is_absolute(path))
else if (git_path_is_absolute(path))
path += PATH__ABSOLUTE_LEN;
} else if (path__is_absolute(path)) {
} else if (git_path_is_absolute(path)) {
path += PATH__ABSOLUTE_LEN;
} else if (path__is_unc(path)) {
path = path__skip_server(path + 2);
......@@ -196,7 +193,7 @@ int git_win32_path_from_utf8(git_win32_path out, const char *src)
dest += PATH__NT_NAMESPACE_LEN;
/* See if this is an absolute path (beginning with a drive letter) */
if (path__is_absolute(src)) {
if (git_path_is_absolute(src)) {
if (git__utf8_to_16(dest, MAX_PATH, src) < 0)
goto on_error;
}
......@@ -220,7 +217,7 @@ int git_win32_path_from_utf8(git_win32_path out, const char *src)
if (path__cwd(dest, MAX_PATH) < 0)
goto on_error;
if (!path__is_absolute(dest)) {
if (!git_path_is_absolute(dest)) {
errno = ENOENT;
goto on_error;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment