diff options
author | pommicket <pommicket@gmail.com> | 2023-10-18 23:47:17 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-10-18 23:47:17 -0400 |
commit | 0dc4d4db3a91faa799187fd321fcae82b12f9b66 (patch) | |
tree | 01450afdc49764bd8ea486d155a351fd7b6a8d4b /util.c | |
parent | 4d57539ffc2954e5c3b9c42da41511f69c4fcde9 (diff) |
editorconfig globs, testing "framework"
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -476,6 +476,29 @@ bool path_is_absolute(const char *path) { ; } +void path_dirname(char *path) { + if (!*path) { + assert(0); // invalid path + return; + } + for (size_t i = strlen(path) - 1; i > 0; --i) { + if (strchr(ALL_PATH_SEPARATORS, path[i])) { + if (strcspn(path, ALL_PATH_SEPARATORS) == i) { + // only one path separator + path[i+1] = '\0'; + return; + } + path[i] = '\0'; + return; + } + } + if (strchr(ALL_PATH_SEPARATORS, path[0])) { + path[1] = '\0'; + return; + } + assert(0); // invalid path (no path separator) +} + void path_full(const char *dir, const char *relpath, char *abspath, size_t abspath_size) { assert(abspath_size); assert(dir[0]); |