From: Lucas De Marchi Date: Mon, 5 Dec 2011 21:58:39 +0000 (-0200) Subject: Split function to search moddep file X-Git-Tag: v1~94 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1eb2ef694c79a5081f5c0c2beae1967c6410f674;p=thirdparty%2Fkmod.git Split function to search moddep file --- diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c index 1ad4e274..da1ea17f 100644 --- a/libkmod/libkmod.c +++ b/libkmod/libkmod.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -345,11 +346,32 @@ int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, static const char *moddep_file = "modules.dep"; +static char *search_moddep(struct kmod_ctx *ctx, const char *name) +{ + struct index_file *idx; + char fn[PATH_MAX]; + char *line; + + snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname, moddep_file); + + DBG(ctx, "file=%s modname=%s\n", fn, name); + + idx = index_file_open(fn); + if (idx == NULL) { + ERR(ctx, "Could not open moddep file '%s'", fn); + return NULL; + } + + line = index_search(idx, name); + index_file_close(idx); + + return line; +} + int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) { - char *fn, *line; - struct index_file *idx; + char *line; int n = 0; /* @@ -359,18 +381,7 @@ int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, if (strchr(name, ':')) return 0; - if (asprintf(&fn, "%s/%s.bin", ctx->dirname, moddep_file) < 0) - return -ENOMEM; - - DBG(ctx, "file=%s modname=%s\n", fn, name); - - idx = index_file_open(fn); - if (idx == NULL) { - free(fn); - return -ENOSYS; - } - - line = index_search(idx, name); + line = search_moddep(ctx, name); if (line != NULL) { struct kmod_module *mod; @@ -386,8 +397,6 @@ int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, finish: free(line); - index_file_close(idx); - free(fn); return n; }