From: Lucas De Marchi Date: Thu, 1 Dec 2011 19:18:24 +0000 (-0200) Subject: Allow path_to_modname to operate locally withou alloc X-Git-Tag: v1~153 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9eaad1f63aecf743b6aa6f1191c43f72b2d52d38;p=thirdparty%2Fkmod.git Allow path_to_modname to operate locally withou alloc --- diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index f28678f0..f864e563 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -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; }