From patchwork Wed Oct 12 07:53:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohan Kumar M X-Patchwork-Id: 119158 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0A496B6F62 for ; Wed, 12 Oct 2011 18:53:57 +1100 (EST) Received: from localhost ([::1]:52035 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDtdR-0007S9-BR for incoming@patchwork.ozlabs.org; Wed, 12 Oct 2011 03:53:53 -0400 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 d23relay03.au.ibm.com ([202.81.31.245]) by au.ibm.com ([202.81.31.206]) with XMail ESMTP; Wed, 12 Oct 2011 08:49:05 +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" To: qemu-devel@nongnu.org Date: Wed, 12 Oct 2011 13:23:33 +0530 Message-Id: <1318406014-16911-1-git-send-email-mohan@in.ibm.com> X-Mailer: git-send-email 1.7.6 x-cbid: 11101122-3568-0000-0000-00000082E7CA X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 202.81.31.142 Subject: [Qemu-devel] [PATCH 1/2] Add opt_set_bool function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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);