aboutsummaryrefslogtreecommitdiffstats
path: root/com32
diff options
context:
space:
mode:
Diffstat (limited to 'com32')
-rw-r--r--com32/elflink/ldlinux/readconfig.c18
-rw-r--r--com32/lib/sys/module/common.c35
2 files changed, 52 insertions, 1 deletions
diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c
index b845d9a8..5bf6f42c 100644
--- a/com32/elflink/ldlinux/readconfig.c
+++ b/com32/elflink/ldlinux/readconfig.c
@@ -27,6 +27,7 @@
#include <dprintf.h>
#include <ctype.h>
#include <core.h>
+#include <fs.h>
#include "menu.h"
#include "config.h"
@@ -1332,6 +1333,23 @@ do_include:
}
} else if (looking_at(p, "say")) {
printf("%s\n", p + 4);
+ } else if (looking_at(p, "path")) {
+ /* PATH-based lookup */
+ char *new_path, *_p;
+ size_t len, new_len;
+
+ new_path = refstrdup(skipspace(p + 4));
+ len = strlen(PATH);
+ new_len = strlen(new_path);
+ _p = realloc(PATH, len + new_len + 2);
+ if (_p) {
+ strncpy(_p, PATH, len);
+ _p[len++] = ':';
+ strncpy(_p + len, new_path, new_len);
+ _p[len + new_len] = '\0';
+ PATH = _p;
+ } else
+ printf("Failed to realloc PATH\n");
}
}
}
diff --git a/com32/lib/sys/module/common.c b/com32/lib/sys/module/common.c
index 431f5cd4..1afdbf5f 100644
--- a/com32/lib/sys/module/common.c
+++ b/com32/lib/sys/module/common.c
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <elf.h>
#include <string.h>
+#include <fs.h>
#include <linux/list.h>
#include <sys/module.h>
@@ -56,13 +57,45 @@ void print_elf_symbols(struct elf_module *module) {
}
#endif //ELF_DEBUG
+static FILE *findpath(char *name)
+{
+ char path[FILENAME_MAX];
+ FILE *f;
+ char *p, *n;
+ int i;
+
+ p = PATH;
+again:
+ i = 0;
+ while (*p && *p != ':' && i < FILENAME_MAX) {
+ path[i++] = *p++;
+ }
+
+ if (*p == ':')
+ p++;
+
+ n = name;
+ while (*n && i < FILENAME_MAX)
+ path[i++] = *n++;
+ path[i] = '\0';
+
+ f = fopen(path, "rb");
+ if (f)
+ return f;
+
+ if (p >= PATH && p < PATH + strlen(PATH))
+ goto again;
+
+ return NULL;
+}
+
/*
* Image files manipulation routines
*/
int image_load(struct elf_module *module)
{
- module->u.l._file = fopen(module->name, "rb");
+ module->u.l._file = findpath(module->name);
if (module->u.l._file == NULL) {
DBG_PRINT("Could not open object file '%s'\n", module->name);