aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-08-13 16:02:45 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-08-13 16:02:45 -0400
commitc9333378605b67a13555f587955a900baf89cb60 (patch)
tree4fd9134ac7d7bd5e8b06eb6b32ee1b7cc0fe4781 /src/utils.c
parent4550b38cd0db6b89c913af0b3444dfd3f1beba36 (diff)
downloadstasis-c9333378605b67a13555f587955a900baf89cb60.tar.gz
Move mkdirs() into utils modulemove-mkdirs
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/utils.c b/src/utils.c
index 70430e1..c0b3733 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -772,4 +772,31 @@ long get_cpu_count() {
#else
return 0;
#endif
-} \ No newline at end of file
+}
+
+int mkdirs(const char *_path, mode_t mode) {
+ int status;
+ char *token;
+ char pathbuf[PATH_MAX] = {0};
+ char *path;
+ path = pathbuf;
+ strcpy(path, _path);
+ errno = 0;
+
+ char result[PATH_MAX] = {0};
+ status = 0;
+ while ((token = strsep(&path, "/")) != NULL && !status) {
+ if (token[0] == '.')
+ continue;
+ strcat(result, token);
+ strcat(result, "/");
+ status = mkdir(result, mode);
+ if (status && errno == EEXIST) {
+ status = 0;
+ errno = 0;
+ continue;
+ }
+ }
+ return status;
+}
+