Allow relative paths for the interpreter prefix in linux-user emulation.
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>
Sun, 17 Jun 2007 15:32:30 +0000 (15:32 +0000)
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>
Sun, 17 Jun 2007 15:32:30 +0000 (15:32 +0000)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2984 c046a42c-6fe2-441c-8c8c-71466251a162

linux-user/path.c

index 7680970..7da0a8b 100644 (file)
@@ -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)
 {