From: Lennart Poettering Date: Sat, 10 Apr 2010 02:38:33 +0000 (+0200) Subject: util: introduce mkdir_p() X-Git-Tag: 0.git+20100605+dfd8ee-1~190 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbd671356647d9d2c7d6c2c0401e907e169c7576;p=systemd util: introduce mkdir_p() --- diff --git a/util.c b/util.c index 3fe59c8e..29f48b08 100644 --- a/util.c +++ b/util.c @@ -728,6 +728,20 @@ int mkdir_parents(const char *path, mode_t mode) { } } +int mkdir_p(const char *path, mode_t mode) { + int r; + + /* Like mkdir -p */ + + if ((r = mkdir_parents(path, mode)) < 0) + return r; + + if (mkdir(path, mode) < 0) + return -errno; + + return 0; +} + char hexchar(int x) { static const char table[16] = "0123456789abcdef"; diff --git a/util.h b/util.h index 4881c981..b22074ed 100644 --- a/util.h +++ b/util.h @@ -137,6 +137,7 @@ char *truncate_nl(char *s); char *file_in_same_dir(const char *path, const char *filename); int mkdir_parents(const char *path, mode_t mode); +int mkdir_p(const char *path, mode_t mode); int get_process_name(pid_t pid, char **name);