]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
util: Add mkdir_parents()
authorLucas De Marchi <lucas.demarchi@intel.com>
Mon, 15 Jul 2013 05:05:52 +0000 (02:05 -0300)
committerLucas De Marchi <lucas.demarchi@intel.com>
Mon, 15 Jul 2013 15:45:35 +0000 (12:45 -0300)
Like mkdir_p, but discards the leaf, creating the parent directories.

libkmod/libkmod-util.c
libkmod/libkmod-util.h

index 1cbc84969211f42e674405960b194cc978d6f808..d6862506b2d904c9c4bf0eb70307a2ba40885256 100644 (file)
@@ -370,6 +370,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
index 4c45416f869dcf5ffbae42be04dcef15df40abd0..f7f3e90d9290d5ab2e254f1fec74944102841133 100644 (file)
@@ -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)));