From bbd671356647d9d2c7d6c2c0401e907e169c7576 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 10 Apr 2010 04:38:33 +0200 Subject: [PATCH] util: introduce mkdir_p() --- util.c | 14 ++++++++++++++ util.h | 1 + 2 files changed, 15 insertions(+) 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); -- 2.39.5