diff options
Diffstat (limited to 'src/util/fs_path.h')
-rw-r--r-- | src/util/fs_path.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util/fs_path.h b/src/util/fs_path.h index e5ca673..43f7951 100644 --- a/src/util/fs_path.h +++ b/src/util/fs_path.h @@ -87,6 +87,29 @@ extern int git_fs_path_to_dir(git_str *path); extern void git_fs_path_string_to_dir(char *path, size_t size); /** + * Provides the length of the given path string with no trailing + * slashes. + */ +size_t git_fs_path_dirlen(const char *path); + +/** + * Returns nonzero if the given path is a filesystem root; on Windows, this + * means a drive letter (eg `A:/`, `C:\`). On POSIX this is `/`. + */ +GIT_INLINE(int) git_fs_path_is_root(const char *name) +{ +#ifdef GIT_WIN32 + if (((name[0] >= 'A' && name[0] <= 'Z') || (name[0] >= 'a' && name[0] <= 'z')) && + name[1] == ':' && + (name[2] == '/' || name[2] == '\\') && + name[3] == '\0') + return 1; +#endif + + return (name[0] == '/' && name[1] == '\0'); +} + +/** * Taken from git.git; returns nonzero if the given path is "." or "..". */ GIT_INLINE(int) git_fs_path_is_dot_or_dotdot(const char *name) |