From 24d2752ad601b4ab48d72b52f602e129dd4761d7 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Wed, 1 Jun 2011 16:50:56 +0200 Subject: vl-android.c: Fix PC Bios search order. This fixes the algorithm used to search the PC Bios files. Moreover, this makes standalone builds under external/qemu just work by looking under prebuilt/common/pc-bios Change-Id: I4619565d57dc5a5b75333f6459f5bfc32b81e918 --- vl-android.c | 76 ++++++++++++++++++++++++------------------------------------ 1 file changed, 30 insertions(+), 46 deletions(-) (limited to 'vl-android.c') diff --git a/vl-android.c b/vl-android.c index 0a64d0d..c240a44 100644 --- a/vl-android.c +++ b/vl-android.c @@ -3550,22 +3550,11 @@ static char *find_datadir(const char *argv0) } #else /* !_WIN32 */ -/* Find a likely location for support files using the location of the binary. - For installed binaries this will be "$bindir/../share/qemu". When - running from the build tree this will be "$bindir/../usr/share/pc-bios". - The emulator running from the SDK will find the support files in $bindir/lib/pc-bios. */ -#define SHARE_SUFFIX "/share/qemu" -#define BUILD_SUFFIX "/usr/share/pc-bios" -#define SDK_SUFFIX "/lib/pc-bios" +/* Similarly, return the location of the executable */ static char *find_datadir(const char *argv0) { - char *dir; char *p = NULL; - char *res; -#ifdef PATH_MAX char buf[PATH_MAX]; -#endif - size_t max_len; #if defined(__linux__) { @@ -3589,46 +3578,33 @@ static char *find_datadir(const char *argv0) /* If we don't have any way of figuring out the actual executable location then try argv[0]. */ if (!p) { -#ifdef PATH_MAX - p = buf; -#endif - p = realpath(argv0, p); + p = realpath(argv0, buf); if (!p) { return NULL; } } -#define STRLEN_CONST(str) (sizeof(str)-1) - dir = dirname(p); - max_len = strlen(dir) + 1 + - MAX(STRLEN_CONST(SDK_SUFFIX), MAX(STRLEN_CONST(SHARE_SUFFIX), STRLEN_CONST(BUILD_SUFFIX))); - res = qemu_mallocz(max_len); + return qemu_strdup(dirname(buf)); +} +#endif - snprintf(res, max_len, "%s%s", dir, SDK_SUFFIX); - if (access(res, R_OK)) { - dir = dirname(dir); +static char* +qemu_find_file_with_subdir(const char* data_dir, const char* subdir, const char* name) +{ + int len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2; + char* buf = qemu_mallocz(len); - snprintf(res, max_len, "%s%s", dir, SHARE_SUFFIX); - if (access(res, R_OK)) { - snprintf(res, max_len, "%s%s", dir, BUILD_SUFFIX); - if (access(res, R_OK)) { - qemu_free(res); - res = NULL; - } - } + snprintf(buf, len, "%s/%s%s", data_dir, subdir, name); + VERBOSE_PRINT(init," trying to find: %s\n", buf); + if (access(buf, R_OK)) { + qemu_free(buf); + return NULL; } -#ifndef PATH_MAX - free(p); -#endif - return res; + return buf; } -#undef SHARE_SUFFIX -#undef BUILD_SUFFIX -#endif char *qemu_find_file(int type, const char *name) { - int len; const char *subdir; char *buf; @@ -3647,13 +3623,21 @@ char *qemu_find_file(int type, const char *name) default: abort(); } - len = strlen(data_dir) + strlen(name) + strlen(subdir) + 2; - buf = qemu_mallocz(len); - snprintf(buf, len, "%s/%s%s", data_dir, subdir, name); - if (access(buf, R_OK)) { - qemu_free(buf); - return NULL; + buf = qemu_find_file_with_subdir(data_dir, subdir, name); +#ifdef CONFIG_ANDROID + if (type == QEMU_FILE_TYPE_BIOS) { + /* This case corresponds to the emulator being used as part of an + * SDK installation. NOTE: data_dir is really $bindir. */ + if (buf == NULL) + buf = qemu_find_file_with_subdir(data_dir, "lib/pc-bios/", name); + /* This case corresponds to platform builds. */ + if (buf == NULL) + buf = qemu_find_file_with_subdir(data_dir, "../usr/share/pc-bios/", name); + /* Finally, try this for standalone builds under external/qemu */ + if (buf == NULL) + buf = qemu_find_file_with_subdir(data_dir, "../../../prebuilt/common/pc-bios/", name); } +#endif return buf; } -- cgit v1.1