[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 37/87] os-posix: simplify os_find_datadir
From: |
Paolo Bonzini |
Subject: |
[PULL 37/87] os-posix: simplify os_find_datadir |
Date: |
Wed, 18 Dec 2019 13:02:03 +0100 |
From: Marc-André Lureau <address@hidden>
Use g_build_filename instead of sprintf, and g_autofree instead of
manual freeing.
Signed-off-by: Marc-André Lureau <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
os-posix.c | 41 +++++++++++++----------------------------
1 file changed, 13 insertions(+), 28 deletions(-)
diff --git a/os-posix.c b/os-posix.c
index 86cffd2..3cd52e1 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -80,41 +80,26 @@ void os_setup_signal_handling(void)
sigaction(SIGTERM, &act, NULL);
}
-/* 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/../pc-bios". */
-#define SHARE_SUFFIX "/share/qemu"
-#define BUILD_SUFFIX "/pc-bios"
+/*
+ * Find a likely location for support files using the location of the binary.
+ * When running from the build tree this will be "$bindir/../pc-bios".
+ * Otherwise, this is CONFIG_QEMU_DATADIR.
+ */
char *os_find_datadir(void)
{
- char *dir, *exec_dir;
- char *res;
- size_t max_len;
+ g_autofree char *exec_dir = NULL;
+ g_autofree char *dir = NULL;
exec_dir = qemu_get_exec_dir();
- if (exec_dir == NULL) {
- return NULL;
- }
- dir = g_path_get_dirname(exec_dir);
-
- max_len = strlen(dir) +
- MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1;
- res = g_malloc0(max_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)) {
- g_free(res);
- res = NULL;
- }
+ g_return_val_if_fail(exec_dir != NULL, NULL);
+
+ dir = g_build_filename(exec_dir, "..", "pc-bios", NULL);
+ if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
+ return g_steal_pointer(&dir);
}
- g_free(dir);
- g_free(exec_dir);
- return res;
+ return g_strdup(CONFIG_QEMU_DATADIR);
}
-#undef SHARE_SUFFIX
-#undef BUILD_SUFFIX
void os_set_proc_name(const char *s)
{
--
1.8.3.1
- [PULL 21/87] qom: introduce object_register_sugar_prop, (continued)
- [PULL 21/87] qom: introduce object_register_sugar_prop, Paolo Bonzini, 2019/12/18
- [PULL 20/87] vl: warn for unavailable accelerators, clarify messages, Paolo Bonzini, 2019/12/18
- [PULL 24/87] tcg: convert "-accel threads" to a QOM property, Paolo Bonzini, 2019/12/18
- [PULL 30/87] Makefile: remove unused variables, Paolo Bonzini, 2019/12/18
- [PULL 27/87] kvm: convert "-machine kvm_shadow_mem" to an accelerator property, Paolo Bonzini, 2019/12/18
- [PULL 35/87] monitor: fix maybe-uninitialized, Paolo Bonzini, 2019/12/18
- [PULL 36/87] vhost-user-scsi: fix printf format warning, Paolo Bonzini, 2019/12/18
- [PULL 38/87] tests: skip block layer tests if !CONFIG_TOOLS, Paolo Bonzini, 2019/12/18
- [PULL 41/87] stubs: replace stubs with lnot if applicable, Paolo Bonzini, 2019/12/18
- [PULL 43/87] configure: simplify vhost condition with Kconfig, Paolo Bonzini, 2019/12/18
- [PULL 37/87] os-posix: simplify os_find_datadir,
Paolo Bonzini <=
- [PULL 39/87] libvixl: remove per-target compiler flags, Paolo Bonzini, 2019/12/18
- [PULL 29/87] kvm: convert "-machine kernel_irqchip" to an accelerator property, Paolo Bonzini, 2019/12/18
- [PULL 40/87] crypto: move common bits for all emulators to libqemuutil, Paolo Bonzini, 2019/12/18
- [PULL 44/87] i386: conditionally compile more files, Paolo Bonzini, 2019/12/18
- [PULL 42/87] configure: set $PYTHON to a full path, Paolo Bonzini, 2019/12/18
- [PULL 45/87] fw_cfg: allow building without other devices, Paolo Bonzini, 2019/12/18
- [PULL 47/87] pci-stub: add more MSI functions, Paolo Bonzini, 2019/12/18
- [PULL 48/87] x86: move SMM property to X86MachineState, Paolo Bonzini, 2019/12/18