From ffb04fcf089865952592f1f8855c2848d4514a89 Mon Sep 17 00:00:00 2001 From: ths Date: Sun, 17 Jun 2007 15:32:30 +0000 Subject: [PATCH] Allow relative paths for the interpreter prefix in linux-user emulation. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2984 c046a42c-6fe2-441c-8c8c-71466251a162 --- linux-user/path.c | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/linux-user/path.c b/linux-user/path.c index 76809705a4..7da0a8b27a 100644 --- a/linux-user/path.c +++ b/linux-user/path.c @@ -92,23 +92,6 @@ static void set_parents(struct pathelem *child, struct pathelem *parent) set_parents(child->entries[i], child); } -void init_paths(const char *prefix) -{ - if (prefix[0] != '/' || - prefix[0] == '\0' || - !strcmp(prefix, "/")) - return; - - base = new_entry("", NULL, prefix+1); - base = add_dir_maybe(base); - if (base->num_entries == 0) { - free (base); - base = NULL; - } else { - set_parents(base, base); - } -} - /* FIXME: Doesn't handle DIR/.. where DIR is not in emulated dir. */ static const char * follow_path(const struct pathelem *cursor, const char *name) @@ -135,6 +118,35 @@ follow_path(const struct pathelem *cursor, const char *name) return NULL; } +void init_paths(const char *prefix) +{ + char pref_buf[PATH_MAX]; + + if (prefix[0] == '\0' || + !strcmp(prefix, "/")) + return; + + if (prefix[0] != '/') { + char *cwd = get_current_dir_name(); + if (!cwd) + abort(); + strcpy(pref_buf, cwd); + strcat(pref_buf, "/"); + strcat(pref_buf, prefix); + free(cwd); + } else + strcpy(pref_buf,prefix + 1); + + base = new_entry("", NULL, pref_buf); + base = add_dir_maybe(base); + if (base->num_entries == 0) { + free (base); + base = NULL; + } else { + set_parents(base, base); + } +} + /* Look for path in emulation dir, otherwise return name. */ const char *path(const char *name) {