From: Karol Lewandowski Date: Fri, 22 Feb 2019 14:22:42 +0000 (+0100) Subject: util: Add make_dir X-Git-Tag: submit/tizen/20190301.131043~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=42e79e989e4047193e6d4bc1a46278c2adf64636;p=platform%2Fcore%2Fsystem%2Fcrash-worker.git util: Add make_dir There is no need to call mkdir(1) for simple cases. Change-Id: Iae4aeff8d78420f5093d946fbfe0daeb7a339b13 --- diff --git a/src/shared/util.c b/src/shared/util.c index 564d276..203d684 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -518,6 +518,20 @@ int fsync_path(char *const path) return ret; } +int make_dir(const char *path, const char *name, int mode) +{ + int r = -1; + + DIR *dir = opendir(path); + if (dir) { + int dfd = dirfd(dir); + r = mkdirat(dfd, name, mode); + closedir(dir); + } + + return r == 0 || (r == -1 && errno == EEXIST) ? 0 : -1; +} + static int remove_dir_internal(int fd) { DIR *dir; diff --git a/src/shared/util.h b/src/shared/util.h index c45bf3c..651a544 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -53,6 +53,8 @@ int run_command_timeout(char *path, char *args[], char *env[], int timeout); int fsync_path(char *const path); +int make_dir(const char *path, const char *name, int mode); + int remove_dir(const char *path, int del_dir); int get_exec_pid(const char *execpath);