]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Allow path_to_modname to operate locally withou alloc
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 1 Dec 2011 19:18:24 +0000 (17:18 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Thu, 1 Dec 2011 19:19:24 +0000 (17:19 -0200)
libkmod/libkmod-module.c

index f28678f0ad61f4139caddb8d48bb260bfa89f2d8..f864e5633f20db9e9068c0ce7270a15a6423082c 100644 (file)
@@ -46,7 +46,7 @@ struct kmod_module {
        const char *name;
 };
 
-static char *path_to_modname(const char *path)
+static char *path_to_modname(const char *path, bool alloc)
 {
        char *modname;
        char *c;
@@ -55,7 +55,9 @@ static char *path_to_modname(const char *path)
        if (modname == NULL || modname[0] == '\0')
                return NULL;
 
-       modname = strdup(modname);
+       if (alloc)
+               modname = strdup(modname);
+
        for (c = modname; *c != '\0' && *c != '.'; c++) {
                if (*c == '-')
                        *c = '_';
@@ -68,7 +70,7 @@ static char *path_to_modname(const char *path)
 static const char *get_modname(struct kmod_module *mod)
 {
        if (mod->name == NULL)
-               mod->name = path_to_modname(mod->path);
+               mod->name = path_to_modname(mod->path, true);
 
        return mod->name;
 }