aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--Makefile.target4
-rw-r--r--bsd-user/qemu.h2
-rw-r--r--linux-user/path.c159
-rw-r--r--linux-user/qemu.h2
-rw-r--r--path.c (renamed from bsd-user/path.c)3
-rw-r--r--qemu-common.h4
7 files changed, 8 insertions, 168 deletions
diff --git a/Makefile b/Makefile
index 5279504..3437989 100644
--- a/Makefile
+++ b/Makefile
@@ -162,7 +162,7 @@ libqemu_common.a: $(obj-y)
#######################################################################
# user-obj-y is code used by qemu userspace emulation
-user-obj-y = cutils.o cache-utils.o
+user-obj-y = cutils.o cache-utils.o path.o
libqemu_user.a: $(user-obj-y)
diff --git a/Makefile.target b/Makefile.target
index 3f5d24a..93c555b 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -86,7 +86,7 @@ ifdef CONFIG_LINUX_USER
VPATH+=:$(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR)
QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR)
-obj-y = main.o syscall.o strace.o mmap.o signal.o path.o thunk.o \
+obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \
elfload.o linuxload.o uaccess.o envlist.o gdbstub.o gdbstub-xml.o \
ioport-user.o
obj-$(TARGET_HAS_BFLT) += flatload.o
@@ -132,7 +132,7 @@ ifdef CONFIG_BSD_USER
VPATH+=:$(SRC_PATH)/bsd-user
QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ARCH)
-obj-y = main.o bsdload.o elfload.o mmap.o path.o signal.o strace.o syscall.o \
+obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \
gdbstub.o gdbstub-xml.o ioport-user.o
obj-y += uaccess.o
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index d375611..cbee3e7 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -137,8 +137,6 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,
void gemu_log(const char *fmt, ...) __attribute__((format(printf,1,2)));
extern THREAD CPUState *thread_env;
void cpu_loop(CPUState *env, enum BSDType bsd_type);
-void init_paths(const char *prefix);
-const char *path(const char *pathname);
char *target_strerror(int err);
int get_osversion(void);
void fork_start(void);
diff --git a/linux-user/path.c b/linux-user/path.c
deleted file mode 100644
index 06b1f5f..0000000
--- a/linux-user/path.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/* Code to mangle pathnames into those matching a given prefix.
- eg. open("/lib/foo.so") => open("/usr/gnemul/i386-linux/lib/foo.so");
-
- The assumption is that this area does not change.
-*/
-#include <sys/types.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <stdio.h>
-#include "qemu.h"
-
-struct pathelem
-{
- /* Name of this, eg. lib */
- char *name;
- /* Full path name, eg. /usr/gnemul/x86-linux/lib. */
- char *pathname;
- struct pathelem *parent;
- /* Children */
- unsigned int num_entries;
- struct pathelem *entries[0];
-};
-
-static struct pathelem *base;
-
-/* First N chars of S1 match S2, and S2 is N chars long. */
-static int strneq(const char *s1, unsigned int n, const char *s2)
-{
- unsigned int i;
-
- for (i = 0; i < n; i++)
- if (s1[i] != s2[i])
- return 0;
- return s2[i] == 0;
-}
-
-static struct pathelem *add_entry(struct pathelem *root, const char *name);
-
-static struct pathelem *new_entry(const char *root,
- struct pathelem *parent,
- const char *name)
-{
- struct pathelem *new = malloc(sizeof(*new));
- new->name = strdup(name);
- asprintf(&new->pathname, "%s/%s", root, name);
- new->num_entries = 0;
- return new;
-}
-
-#define streq(a,b) (strcmp((a), (b)) == 0)
-
-static struct pathelem *add_dir_maybe(struct pathelem *path)
-{
- DIR *dir;
-
- if ((dir = opendir(path->pathname)) != NULL) {
- struct dirent *dirent;
-
- while ((dirent = readdir(dir)) != NULL) {
- if (!streq(dirent->d_name,".") && !streq(dirent->d_name,"..")){
- path = add_entry(path, dirent->d_name);
- }
- }
- closedir(dir);
- }
- return path;
-}
-
-static struct pathelem *add_entry(struct pathelem *root, const char *name)
-{
- root->num_entries++;
-
- root = realloc(root, sizeof(*root)
- + sizeof(root->entries[0])*root->num_entries);
-
- root->entries[root->num_entries-1] = new_entry(root->pathname, root, name);
- root->entries[root->num_entries-1]
- = add_dir_maybe(root->entries[root->num_entries-1]);
- return root;
-}
-
-/* This needs to be done after tree is stabilized (ie. no more reallocs!). */
-static void set_parents(struct pathelem *child, struct pathelem *parent)
-{
- unsigned int i;
-
- child->parent = parent;
- for (i = 0; i < child->num_entries; i++)
- set_parents(child->entries[i], child);
-}
-
-/* FIXME: Doesn't handle DIR/.. where DIR is not in emulated dir. */
-static const char *
-follow_path(const struct pathelem *cursor, const char *name)
-{
- unsigned int i, namelen;
-
- name += strspn(name, "/");
- namelen = strcspn(name, "/");
-
- if (namelen == 0)
- return cursor->pathname;
-
- if (strneq(name, namelen, ".."))
- return follow_path(cursor->parent, name + namelen);
-
- if (strneq(name, namelen, "."))
- return follow_path(cursor, name + namelen);
-
- for (i = 0; i < cursor->num_entries; i++)
- if (strneq(name, namelen, cursor->entries[i]->name))
- return follow_path(cursor->entries[i], name + namelen);
-
- /* Not found */
- 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)
-{
- /* Only do absolute paths: quick and dirty, but should mostly be OK.
- Could do relative by tracking cwd. */
- if (!base || !name || name[0] != '/')
- return name;
-
- return follow_path(base, name) ?: name;
-}
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index f0e410b..def620f 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -190,8 +190,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
void gemu_log(const char *fmt, ...) __attribute__((format(printf,1,2)));
extern THREAD CPUState *thread_env;
void cpu_loop(CPUState *env);
-void init_paths(const char *prefix);
-const char *path(const char *pathname);
char *target_strerror(int err);
int get_osversion(void);
void fork_start(void);
diff --git a/bsd-user/path.c b/path.c
index 5c40ec7..cc9e007 100644
--- a/bsd-user/path.c
+++ b/path.c
@@ -11,7 +11,6 @@
#include <string.h>
#include <errno.h>
#include <stdio.h>
-#include "qemu.h"
#include "qemu-common.h"
struct pathelem
@@ -156,7 +155,7 @@ const char *path(const char *name)
{
/* Only do absolute paths: quick and dirty, but should mostly be OK.
Could do relative by tracking cwd. */
- if (!base || name[0] != '/')
+ if (!base || !name || name[0] != '/')
return name;
return follow_path(base, name) ?: name;
diff --git a/qemu-common.h b/qemu-common.h
index c1fb5bf..74ac88f 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -115,6 +115,10 @@ int qemu_strnlen(const char *s, int max_len);
time_t mktimegm(struct tm *tm);
int qemu_fls(int i);
+/* path.c */
+void init_paths(const char *prefix);
+const char *path(const char *pathname);
+
#define qemu_isalnum(c) isalnum((unsigned char)(c))
#define qemu_isalpha(c) isalpha((unsigned char)(c))
#define qemu_iscntrl(c) iscntrl((unsigned char)(c))