From: Lucas De Marchi <lucas.demarchi@xxxxxxxxx> Like mkdir_p, but discard the leaf and create all parent directories. --- libkmod/libkmod-util.c | 11 +++++++++++ libkmod/libkmod-util.h | 1 + 2 files changed, 12 insertions(+) diff --git a/libkmod/libkmod-util.c b/libkmod/libkmod-util.c index 45ca11a..764c551 100644 --- a/libkmod/libkmod-util.c +++ b/libkmod/libkmod-util.c @@ -373,6 +373,17 @@ int mkdir_p(const char *path, int len, mode_t mode) return 0; } +int mkdir_parents(const char *path, mode_t mode) +{ + char *end = strrchr(path, '/'); + + /* no parent directories */ + if (end == NULL) + return 0; + + return mkdir_p(path, end - path, mode); +} + const struct kmod_ext kmod_exts[] = { {".ko", sizeof(".ko") - 1}, #ifdef ENABLE_ZLIB diff --git a/libkmod/libkmod-util.h b/libkmod/libkmod-util.h index 4c45416..f7f3e90 100644 --- a/libkmod/libkmod-util.h +++ b/libkmod/libkmod-util.h @@ -21,6 +21,7 @@ char *strchr_replace(char *s, int c, char r); bool path_is_absolute(const char *p) _must_check_ __attribute__((nonnull(1))); char *path_make_absolute_cwd(const char *p) _must_check_ __attribute__((nonnull(1))); int mkdir_p(const char *path, int len, mode_t mode); +int mkdir_parents(const char *path, mode_t mode); int alias_normalize(const char *alias, char buf[PATH_MAX], size_t *len) _must_check_ __attribute__((nonnull(1,2))); char *modname_normalize(const char *modname, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(1, 2))); char *path_to_modname(const char *path, char buf[PATH_MAX], size_t *len) __attribute__((nonnull(2))); -- 1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-modules" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html