return NULL;
}
-static int id_wellformed(const char *id)
-{
- int i;
-
- if (!qemu_isalpha(id[0])) {
- return 0;
- }
- for (i = 1; id[i]; i++) {
- if (!qemu_isalnum(id[i]) && !strchr("-._", id[i])) {
- return 0;
- }
- }
- return 1;
-}
-
QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
int fail_if_exists, Error **errp)
{
g_free(opts);
}
-void qemu_opts_print(QemuOpts *opts)
+void qemu_opts_print(QemuOpts *opts, const char *sep)
{
QemuOpt *opt;
QemuOptDesc *desc = opts->list->desc;
if (desc[0].name == NULL) {
QTAILQ_FOREACH(opt, &opts->head, next) {
- printf("%s=\"%s\" ", opt->name, opt->str);
+ printf("%s%s=\"%s\"", sep, opt->name, opt->str);
}
return;
}
continue;
}
if (desc->type == QEMU_OPT_STRING) {
- printf("%s='%s' ", desc->name, value);
+ printf("%s%s='%s'", sep, desc->name, value);
} else if ((desc->type == QEMU_OPT_SIZE ||
desc->type == QEMU_OPT_NUMBER) && opt) {
- printf("%s=%" PRId64 " ", desc->name, opt->value.uint);
+ printf("%s%s=%" PRId64, sep, desc->name, opt->value.uint);
} else {
- printf("%s=%s ", desc->name, value);
+ printf("%s%s=%s", sep, desc->name, value);
}
}
}
size_t num_opts, num_dst_opts;
QemuOptDesc *desc;
bool need_init = false;
+ bool need_head_update;
if (!list) {
return dst;
*/
if (!dst) {
need_init = true;
+ need_head_update = true;
+ } else {
+ /* Moreover, even if dst is not NULL, the realloc may move it to a
+ * different address in which case we may get a stale tail pointer
+ * in dst->head. */
+ need_head_update = QTAILQ_EMPTY(&dst->head);
}
num_opts = count_opts_list(dst);
if (need_init) {
dst->name = NULL;
dst->implied_opt_name = NULL;
- QTAILQ_INIT(&dst->head);
dst->merge_lists = false;
}
+ if (need_head_update) {
+ QTAILQ_INIT(&dst->head);
+ }
dst->desc[num_dst_opts].name = NULL;
/* append list->desc to dst->desc */