From: Lucas De Marchi Date: Tue, 6 Dec 2011 11:01:01 +0000 (-0200) Subject: Split function so we don't call basename() unnecessarily X-Git-Tag: v1~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c343b1aeecd8bdcb8aeaa186b6d1075d8ce785d;p=thirdparty%2Fkmod.git Split function so we don't call basename() unnecessarily --- diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 432f453f..25ca5d9d 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -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) {