]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
util: Add len arg to mkdir_p()
authorLucas De Marchi <lucas.demarchi@intel.com>
Mon, 15 Jul 2013 04:58:44 +0000 (01:58 -0300)
committerLucas De Marchi <lucas.demarchi@intel.com>
Mon, 15 Jul 2013 15:44:33 +0000 (12:44 -0300)
libkmod/libkmod-util.c
libkmod/libkmod-util.h
testsuite/init_module.c

index 43d8b02a3d994ad51e68476cb8fc2ddcdaca0b67..1cbc84969211f42e674405960b194cc978d6f808 100644 (file)
@@ -320,11 +320,12 @@ static inline int is_dir(const char *path)
        return -errno;
 }
 
-int mkdir_p(const char *path, mode_t mode)
+int mkdir_p(const char *path, int len, mode_t mode)
 {
-       char *start = strdupa(path);
-       int len = strlen(path);
-       char *end = start + len;
+       char *start, *end;
+
+       start = strndupa(path, len);
+       end = start + len;
 
        /*
         * scan backwards, replacing '/' with '\0' while the component doesn't
index 83c975cccc5eb461fd5c8bcb8e08f744d095d327..4c45416f869dcf5ffbae42be04dcef15df40abd0 100644 (file)
@@ -20,7 +20,7 @@ int read_str_ulong(int fd, unsigned long *value, int base) _must_check_ __attrib
 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, mode_t mode);
+int mkdir_p(const char *path, int len, 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)));
index ebf1b9439a0e6635f57dc63fdecd6bd571689b8b..42177e76f3f5c19d2e31ead91560193b8247faf0 100644 (file)
@@ -155,7 +155,7 @@ static int create_sysfs_files(const char *modname)
        strcpy(buf + len, modname);
        len += strlen(modname);
 
-       assert(mkdir_p(buf, 0755) >= 0);
+       assert(mkdir_p(buf, len, 0755) >= 0);
 
        strcpy(buf + len, "/initstate");
        return write_one_line_file(buf, "live\n", strlen("live\n"));