]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Split function so we don't call basename() unnecessarily
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 6 Dec 2011 11:01:01 +0000 (09:01 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Tue, 6 Dec 2011 11:02:13 +0000 (09:02 -0200)
libkmod/libkmod-module.c

index 432f453f713b96fd6dd7926dd09a2d1da892f2be..25ca5d9d0abbf5421086efbd8dd884c6b8021429 100644 (file)
@@ -53,16 +53,12 @@ struct kmod_module {
        char name[];
 };
 
-static char *path_to_modname(const char *path, char buf[NAME_MAX], size_t *len)
+static inline char *modname_normalize(char *modname, char buf[NAME_MAX],
+                                                               size_t *len)
 {
-       char *modname;
        char *c;
        size_t s;
 
-       modname = basename(path);
-       if (modname == NULL || modname[0] == '\0')
-               return NULL;
-
        if (buf) {
                buf[NAME_MAX] = '\0';
                modname = strncpy(buf, modname, NAME_MAX - 1);
@@ -82,6 +78,17 @@ static char *path_to_modname(const char *path, char buf[NAME_MAX], size_t *len)
        return modname;
 }
 
+static char *path_to_modname(const char *path, char buf[NAME_MAX], size_t *len)
+{
+       char *modname;
+
+       modname = basename(path);
+       if (modname == NULL || modname[0] == '\0')
+               return NULL;
+
+       return modname_normalize(modname, buf, len);
+}
+
 int kmod_module_parse_depline(struct kmod_module *mod, char *line)
 {
        struct kmod_ctx *ctx = mod->ctx;
@@ -142,7 +149,7 @@ KMOD_EXPORT int kmod_module_new_from_name(struct kmod_ctx *ctx,
        if (ctx == NULL || name == NULL)
                return -ENOENT;
 
-       path_to_modname(name, name_norm, &namelen);
+       modname_normalize((char *)name, name_norm, &namelen);
 
        m = kmod_pool_get_module(ctx, name_norm);
        if (m != NULL) {