kmod_load_resources: use proper full path to binary files to be mmaped.
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Sat, 10 Dec 2011 12:27:27 +0000 (10:27 -0200)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Sat, 10 Dec 2011 12:27:27 +0000 (10:27 -0200)
libkmod/libkmod.c

index 8e4209d..b56a309 100644 (file)
@@ -560,6 +560,7 @@ fail:
 
 KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx)
 {
+       char path[PATH_MAX];
        size_t i;
 
        if (ctx == NULL)
@@ -568,6 +569,19 @@ KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx)
        for (i = 0; i < ARRAY_SIZE(index_files); i++) {
                if (ctx->indexes[i] == NULL) {
                        const char *fn = index_files[i];
+                       size_t fnlen = strlen(fn);
+                       const char *prefix = "";
+                       const char *suffix = "";
+
+                       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);
                        if (ctx->indexes[i] == NULL)