From 10f5bff622cad71645e22c027b77ac31e51008ef Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 10 Feb 2014 14:48:51 +0800 Subject: util: Split out exec_dir from os_find_datadir With this change, main() calls qemu_init_exec_dir and uses argv[0] to init exec_dir. The saved value can be retrieved with qemu_get_exec_dir later. It will be reused by module loading. Signed-off-by: Fam Zheng Signed-off-by: Paolo Bonzini --- util/oslib-win32.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'util/oslib-win32.c') diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 50be044..93f7d35 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -208,3 +208,33 @@ void qemu_set_tty_echo(int fd, bool echo) dwMode & ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT)); } } + +static char exec_dir[PATH_MAX]; + +void qemu_init_exec_dir(const char *argv0) +{ + + char *p; + char buf[MAX_PATH]; + DWORD len; + + len = GetModuleFileName(NULL, buf, sizeof(buf) - 1); + if (len == 0) { + return; + } + + buf[len] = 0; + p = buf + len - 1; + while (p != buf && *p != '\\') { + p--; + } + *p = 0; + if (access(buf, R_OK) == 0) { + pstrcpy(exec_dir, sizeof(exec_dir), buf); + } +} + +char *qemu_get_exec_dir(void) +{ + return g_strdup(exec_dir); +} -- cgit v1.1