aboutsummaryrefslogtreecommitdiffstats
path: root/vl-android.c
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@android.com>2011-06-01 16:50:56 +0200
committerDavid 'Digit' Turner <digit@android.com>2011-06-01 16:51:52 +0200
commit24d2752ad601b4ab48d72b52f602e129dd4761d7 (patch)
treefcee4fcd71d56ee4dba5310a9e9b50d498f90020 /vl-android.c
parentfe1ecda2a81e17dceddd7dd195ec0b026c872279 (diff)
downloadexternal_qemu-24d2752ad601b4ab48d72b52f602e129dd4761d7.zip
external_qemu-24d2752ad601b4ab48d72b52f602e129dd4761d7.tar.gz
external_qemu-24d2752ad601b4ab48d72b52f602e129dd4761d7.tar.bz2
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
Diffstat (limited to 'vl-android.c')
-rw-r--r--vl-android.c76
1 files changed, 30 insertions, 46 deletions
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;
}