summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-04-10 04:38:33 +0200
committerLennart Poettering <lennart@poettering.net>2010-04-10 04:38:33 +0200
commitbbd671356647d9d2c7d6c2c0401e907e169c7576 (patch)
tree34bd9909db3e2bc667490ff4c9a7f8d5decdea46
parente05797fba258d7a58987cc8870fae6e34b94fe46 (diff)
util: introduce mkdir_p()
-rw-r--r--util.c14
-rw-r--r--util.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/util.c b/util.c
index 3fe59c8ebb..29f48b08e3 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 4881c981b9..b22074edec 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);