Received: from eggs.gnu.org ([140.186.70.92]:44016) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDtdJ-0007Rv-Mh for qemu-devel@nongnu.org; Wed, 12 Oct 2011 03:53:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RDtdI-0007Iw-9q for qemu-devel@nongnu.org; Wed, 12 Oct 2011 03:53:45 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:60038) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDtdH-0007I9-PQ for qemu-devel@nongnu.org; Wed, 12 Oct 2011 03:53:44 -0400 Received: from /spool/local by au.ibm.com with XMail ESMTP for from ; Wed, 12 Oct 2011 08:49:06 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p9C7rab71511624 for ; Wed, 12 Oct 2011 18:53:36 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p9C7raeo003004 for ; Wed, 12 Oct 2011 18:53:36 +1100 Received: from explorer.in.ibm.com ([9.122.21.24]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p9C7rZUQ002986 for ; Wed, 12 Oct 2011 18:53:35 +1100 From: "M. Mohan Kumar" Date: Wed, 12 Oct 2011 13:23:33 +0530 Message-Id: <1318406014-16911-1-git-send-email-mohan@in.ibm.com> Subject: [Qemu-devel] [PATCH 1/2] Add opt_set_bool function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org In addition to qemu_opt_set function, we need a function to set bool value also. Signed-off-by: M. Mohan Kumar --- qemu-option.c | 35 +++++++++++++++++++++++++++++++++++ qemu-option.h | 1 + 2 files changed, 36 insertions(+), 0 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 105d760..d6bc908 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -636,6 +636,41 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value) return 0; } +int qemu_opt_set_bool(QemuOpts *opts, const char *name, int val) +{ + QemuOpt *opt; + const QemuOptDesc *desc = opts->list->desc; + int i; + + for (i = 0; desc[i].name != NULL; i++) { + if (strcmp(desc[i].name, name) == 0) { + break; + } + } + if (desc[i].name == NULL) { + if (i == 0) { + /* empty list -> allow any */; + } else { + qerror_report(QERR_INVALID_PARAMETER, name); + return -1; + } + } + + opt = g_malloc0(sizeof(*opt)); + opt->name = g_strdup(name); + opt->opts = opts; + QTAILQ_INSERT_TAIL(&opts->head, opt, next); + if (desc[i].name != NULL) { + opt->desc = desc+i; + } + opt->value.boolean = !!val; + if (qemu_opt_parse(opt) < 0) { + qemu_opt_del(opt); + return -1; + } + return 0; +} + int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, int abort_on_failure) { diff --git a/qemu-option.h b/qemu-option.h index b515813..af4d36b 100644 --- a/qemu-option.h +++ b/qemu-option.h @@ -109,6 +109,7 @@ int qemu_opt_get_bool(QemuOpts *opts, const char *name, int defval); uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval); uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval); int qemu_opt_set(QemuOpts *opts, const char *name, const char *value); +int qemu_opt_set_bool(QemuOpts *opts, const char *name, int val); typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque); int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, int abort_on_failure); -- 1.7.6