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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
diff --git a/src/path.h b/src/path.h
index 360372c..d674b1b 100644
--- a/src/path.h
+++ b/src/path.h
@@ -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
/**
diff --git a/src/win32/path_w32.c b/src/win32/path_w32.c
index f8416b8..8cea48b 100644
--- a/src/win32/path_w32.c
+++ b/src/win32/path_w32.c
@@ -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;
}