From b2a9cfafc577533b0a9923d93c0bd8039eaf9b50 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Fri, 5 Aug 2022 13:29:40 -0300 Subject: misc: Fixed a major issue with `mkdirp()` It was basically not properly skipping over to the next forward slash. The solution was to have it get the span of the forward slashes, and checking if we hit the null terminator after trying to find the next forward slash. If we do hit the null terminator, we add the forward slash span to the cursor. --- misc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/misc.c b/misc.c index 12fdd2a..4a5f6be 100644 --- a/misc.c +++ b/misc.c @@ -251,7 +251,8 @@ int is_dir(const char *path) { void mkdirp(const char *path, int mode) { char *str = make_str(path); - for (char *p = find_delm(str, "/", *str == '/'); !is_empty(p); p = find_delm(p, "/", 1)) { + for (char *p = find_delm(str, "/", *str == '/'); !is_empty(p); p = find_delm(p, "/", *p == '/')) { + const size_t span = strspn(p, "/"); if (*p == '/') { *p = '\0'; } @@ -260,6 +261,9 @@ void mkdirp(const char *path, int mode) { } if (*p == '\0') { *p = '/'; + if (*find_delm(&p[span], "/", 0) != '\0') { + p += span; + } } } -- cgit v1.2.3-13-gbd6f