aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/oslib-posix.c23
-rw-r--r--util/oslib-win32.c4
2 files changed, 11 insertions, 16 deletions
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 18531fc859..1739930e65 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -358,15 +358,14 @@ void qemu_set_tty_echo(int fd, bool echo)
tcsetattr(fd, TCSANOW, &tty);
}
-static char exec_dir[PATH_MAX];
+static const char *exec_dir;
void qemu_init_exec_dir(const char *argv0)
{
- char *dir;
char *p = NULL;
char buf[PATH_MAX];
- if (exec_dir[0]) {
+ if (exec_dir) {
return;
}
@@ -425,20 +424,14 @@ void qemu_init_exec_dir(const char *argv0)
#endif
/* If we don't have any way of figuring out the actual executable
location then try argv[0]. */
- if (!p) {
- if (!argv0) {
- return;
- }
+ if (!p && argv0) {
p = realpath(argv0, buf);
- if (!p) {
- return;
- }
}
- dir = g_path_get_dirname(p);
-
- pstrcpy(exec_dir, sizeof(exec_dir), dir);
-
- g_free(dir);
+ if (p) {
+ exec_dir = g_path_get_dirname(p);
+ } else {
+ exec_dir = CONFIG_BINDIR;
+ }
}
const char *qemu_get_exec_dir(void)
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 1a33912944..051afb217b 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -315,7 +315,7 @@ void qemu_set_tty_echo(int fd, bool echo)
}
}
-static char *exec_dir;
+static const char *exec_dir;
void qemu_init_exec_dir(const char *argv0)
{
@@ -341,6 +341,8 @@ void qemu_init_exec_dir(const char *argv0)
*p = 0;
if (access(buf, R_OK) == 0) {
exec_dir = g_strdup(buf);
+ } else {
+ exec_dir = CONFIG_BINDIR;
}
}