]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Simplify kmod_load_resources()
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 14 Dec 2011 05:58:31 +0000 (03:58 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Wed, 14 Dec 2011 12:53:10 +0000 (10:53 -0200)
We have a static vector of indexes. There's no need to check if they
have a suffix or if they are absolute, we just already know in advance
and there are no plans to change it.

libkmod/libkmod.c

index ab6415c1f6b1b20ac19f3f0854fc9e58345446b9..e9ffd50607a919c9b076f0be9f0ec2fd003784de 100644 (file)
@@ -608,34 +608,22 @@ fail:
  */
 KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx)
 {
-       char path[PATH_MAX];
        size_t i;
 
        if (ctx == NULL)
                return -ENOENT;
 
        for (i = 0; i < ARRAY_SIZE(index_files); i++) {
-               const char *fn = index_files[i];
-               size_t fnlen = strlen(fn);
-               const char *prefix = "";
-               const char *suffix = "";
+               char path[PATH_MAX];
 
                if (ctx->indexes[i] == NULL) {
-                       INFO(ctx, "Index %s already loaded\n", fn);
+                       INFO(ctx, "Index %s already loaded\n", index_files[i]);
                        continue;
                }
 
-               if (fn[0] != '/')
-                       prefix = ctx->dirname;
-
-               if (fnlen < 4 || !streq(fn + fnlen - 4, ".bin"))
-                       suffix = ".bin";
-
-               snprintf(path, sizeof(path), "%s/%s%s",
-                               prefix, fn, suffix);
-               fn = path;
-
-               ctx->indexes[i] = index_mm_open(ctx, fn, true);
+               snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname,
+                                                       index_files[i]);
+               ctx->indexes[i] = index_mm_open(ctx, path, true);
                if (ctx->indexes[i] == NULL)
                        goto fail;
        }