summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-08-05 13:29:40 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2022-08-05 13:29:40 -0300
commitb2a9cfafc577533b0a9923d93c0bd8039eaf9b50 (patch)
tree6dbd0243931a2a9b9f378c3936bc2f3b1aba175d /misc.c
parent39f6692f5b61399091ce4d5a318c5621a4a284ac (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.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c6
1 files changed, 5 insertions, 1 deletions
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;
+ }
}
}