util: introduce mkdir_p()

This commit is contained in:
Lennart Poettering 2010-04-10 04:38:33 +02:00
parent e05797fba2
commit bbd6713566
2 changed files with 15 additions and 0 deletions

14
util.c
View File

@ -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";

1
util.h
View File

@ -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);