summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-10-18 23:47:17 -0400
committerpommicket <pommicket@gmail.com>2023-10-18 23:47:17 -0400
commit0dc4d4db3a91faa799187fd321fcae82b12f9b66 (patch)
tree01450afdc49764bd8ea486d155a351fd7b6a8d4b /util.c
parent4d57539ffc2954e5c3b9c42da41511f69c4fcde9 (diff)
editorconfig globs, testing "framework"
Diffstat (limited to 'util.c')
-rw-r--r--util.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/util.c b/util.c
index b86a4ca..2e702e2 100644
--- a/util.c
+++ b/util.c
@@ -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]);