From c9333378605b67a13555f587955a900baf89cb60 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 13 Aug 2024 16:02:45 -0400 Subject: Move mkdirs() into utils module --- src/copy.c | 26 -------------------------- src/utils.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 27 deletions(-) (limited to 'src') 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; +} + -- cgit