sandbox: Add a function to load a relative file path
At present this implementation is specific to loading the test FDT. We
plan to load others, so create a generic function to handle this.
The path is now limited to 256 characters, to simplify the code.
When there is an empty argv[0] (which should not happen), the function now
just uses the path as is, with no prefix.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index 90a84e9..642be16 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -205,21 +205,19 @@
static int sandbox_cmdline_cb_test_fdt(struct sandbox_state *state,
const char *arg)
{
- const char *fmt = "/arch/sandbox/dts/test.dtb";
- char *p;
+ char buf[256];
char *fname;
int len;
- len = strlen(state->argv[0]) + strlen(fmt) + 1;
+ len = state_get_rel_filename("arch/sandbox/dts/test.dtb", buf,
+ sizeof(buf));
+ if (len < 0)
+ return len;
+
fname = os_malloc(len);
if (!fname)
return -ENOMEM;
- strcpy(fname, state->argv[0]);
- p = strrchr(fname, '/');
- if (!p)
- p = fname + strlen(fname);
- len -= p - fname;
- snprintf(p, len, fmt);
+ strcpy(fname, buf);
state->fdt_fname = fname;
return 0;