aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2024-08-13 17:42:35 -0400
committerGitHub <noreply@github.com>2024-08-13 17:42:35 -0400
commitd943633d4d925d7340708371be8abb09adf579fe (patch)
tree4fd9134ac7d7bd5e8b06eb6b32ee1b7cc0fe4781
parent4550b38cd0db6b89c913af0b3444dfd3f1beba36 (diff)
downloadstasis-d943633d4d925d7340708371be8abb09adf579fe.tar.gz
Move mkdirs() into utils module (#26)
-rw-r--r--include/copy.h8
-rw-r--r--include/utils.h8
-rw-r--r--src/copy.c26
-rw-r--r--src/utils.c29
4 files changed, 36 insertions, 35 deletions
diff --git a/include/copy.h b/include/copy.h
index 609a6cf..a26ac30 100644
--- a/include/copy.h
+++ b/include/copy.h
@@ -32,14 +32,6 @@
int copytree(const char *srcdir, const char *destdir, unsigned op);
/**
- * Create all leafs in directory path
- * @param _path directory path to create
- * @param mode mode_t permissions
- * @return
- */
-int mkdirs(const char *_path, mode_t mode);
-
-/**
* Copy a single file
*
* ```c
diff --git a/include/utils.h b/include/utils.h
index eee2e30..a3d244a 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -357,4 +357,12 @@ struct StrList *listdir(const char *path);
*/
long get_cpu_count();
+/**
+ * Create all leafs in directory path
+ * @param _path directory path to create
+ * @param mode mode_t permissions
+ * @return
+ */
+int mkdirs(const char *_path, mode_t mode);
+
#endif //STASIS_UTILS_H
diff --git a/src/copy.c b/src/copy.c
index 323208b..7a397e6 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -85,32 +85,6 @@ int copy2(const char *src, const char *dest, unsigned int op) {
return 0;
}
-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;
-}
-
int copytree(const char *srcdir, const char *destdir, unsigned int op) {
DIR *dir;
struct dirent *d;
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;
+}
+