summaryrefslogtreecommitdiff
path: root/vl.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2017-09-14 13:42:35 +0200
committerGerd Hoffmann <kraxel@redhat.com>2017-09-26 13:05:28 +0200
commit2a1cce9058698d384b7c1b6c6b744d928d32dfba (patch)
tree6ea4e450f55a990bd9855e09a66f520627b8e299 /vl.c
parent1e3ee834083227f552179f6e43902cba5a866e6b (diff)
downloadqemu-2a1cce9058698d384b7c1b6c6b744d928d32dfba.tar.gz
add qemu_add_data_dir()
Add helper function to add a directory to the qemu search path, so we don't duplicate the checks. Add a check for duplicate entries, so we stop trying to open files twice. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Message-id: 20170914114236.25343-2-kraxel@redhat.com
Diffstat (limited to 'vl.c')
-rw-r--r--vl.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/vl.c b/vl.c
index 4fd01fda91..19633423aa 100644
--- a/vl.c
+++ b/vl.c
@@ -2348,6 +2348,24 @@ char *qemu_find_file(int type, const char *name)
return NULL;
}
+static void qemu_add_data_dir(const char *path)
+{
+ int i;
+
+ if (path == NULL) {
+ return;
+ }
+ if (data_dir_idx == ARRAY_SIZE(data_dir)) {
+ return;
+ }
+ for (i = 0; i < data_dir_idx; i++) {
+ if (strcmp(data_dir[i], path) == 0) {
+ return; /* duplicate */
+ }
+ }
+ data_dir[data_dir_idx++] = path;
+}
+
static inline bool nonempty_str(const char *str)
{
return str && *str;
@@ -3527,8 +3545,8 @@ int main(int argc, char **argv, char **envp)
case QEMU_OPTION_L:
if (is_help_option(optarg)) {
list_data_dirs = true;
- } else if (data_dir_idx < ARRAY_SIZE(data_dir)) {
- data_dir[data_dir_idx++] = optarg;
+ } else {
+ qemu_add_data_dir(optarg);
}
break;
case QEMU_OPTION_bios:
@@ -4293,16 +4311,10 @@ int main(int argc, char **argv, char **envp)
/* If no data_dir is specified then try to find it relative to the
executable path. */
- if (data_dir_idx < ARRAY_SIZE(data_dir)) {
- data_dir[data_dir_idx] = os_find_datadir();
- if (data_dir[data_dir_idx] != NULL) {
- data_dir_idx++;
- }
- }
+ qemu_add_data_dir(os_find_datadir());
+
/* If all else fails use the install path specified when building. */
- if (data_dir_idx < ARRAY_SIZE(data_dir)) {
- data_dir[data_dir_idx++] = CONFIG_QEMU_DATADIR;
- }
+ qemu_add_data_dir(CONFIG_QEMU_DATADIR);
/* -L help lists the data directories and exits. */
if (list_data_dirs) {