diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2022-08-05 13:29:40 -0300 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2022-08-05 13:29:40 -0300 |
commit | b2a9cfafc577533b0a9923d93c0bd8039eaf9b50 (patch) | |
tree | 6dbd0243931a2a9b9f378c3936bc2f3b1aba175d | |
parent | 39f6692f5b61399091ce4d5a318c5621a4a284ac (diff) |
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.
-rw-r--r-- | misc.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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; + } } } |