util: Add make_dir 84/200384/4
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 22 Feb 2019 14:22:42 +0000 (15:22 +0100)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 26 Feb 2019 15:46:40 +0000 (15:46 +0000)
There is no need to call mkdir(1) for simple cases.

Change-Id: Iae4aeff8d78420f5093d946fbfe0daeb7a339b13

src/shared/util.c
src/shared/util.h

index 564d276..203d684 100644 (file)
@@ -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;
index c45bf3c..651a544 100644 (file)
@@ -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);