From patchwork Thu Dec 6 06:47:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 204151 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1F2672C0134 for ; Thu, 6 Dec 2012 17:49:24 +1100 (EST) Received: from localhost ([::1]:59798 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgVGs-0000vn-AS for incoming@patchwork.ozlabs.org; Thu, 06 Dec 2012 01:49:22 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgVFa-0006QG-3n for qemu-devel@nongnu.org; Thu, 06 Dec 2012 01:48:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TgVFY-0005LW-N8 for qemu-devel@nongnu.org; Thu, 06 Dec 2012 01:48:01 -0500 Received: from mail-ie0-f179.google.com ([209.85.223.179]:51184) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgVFY-0005LQ-Jb for qemu-devel@nongnu.org; Thu, 06 Dec 2012 01:48:00 -0500 Received: by mail-ie0-f179.google.com with SMTP id k14so9575193iea.24 for ; Wed, 05 Dec 2012 22:48:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=T9WMV43hr/2wqWa14sOw97hqx9E49GLFJD5mC2jqtUY=; b=TGyFcR4YThdi8GZ8qIJqjCnZLxzm9cn19StOqkEJWtGhllm9hhf4ZsxF94H3vUubXm yvp+uKuTPhmIGtxcw0Gf1S1baql9jj1Oxx3mJao+SYHk+goux1PwYa4/z6mazpsF7K8n jWY+vkv7QyS7okYSxPz0SlQP6d3FzvFRqoDSKwSuABW4D6RVTUSWvV5uM6te/0oXltwS MyrXbfdS5KcOq+LbrIWq+eqMTXYTjGA+glwUlNyFVU9j82Mki7kf95ec/+N14ohv4qia UvhUXLQtvI+FVOwmqJFI6Jbc7UST/OYaL6vYBASFrThkvjZ+fzQfK/jaix3iKDKMlX9I KW2A== Received: by 10.50.57.166 with SMTP id j6mr428882igq.61.1354776480016; Wed, 05 Dec 2012 22:48:00 -0800 (PST) Received: from localhost.localdomain ([202.108.130.153]) by mx.google.com with ESMTPS id kp4sm6494017igc.1.2012.12.05.22.47.57 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Dec 2012 22:47:59 -0800 (PST) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Thu, 6 Dec 2012 14:47:23 +0800 Message-Id: <1354776447-12041-7-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1354776447-12041-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1354776447-12041-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.223.179 Cc: kwolf@redhat.com, Dong Xu Wang Subject: [Qemu-devel] [PATCH V7 06/10] create new function: qemu_opt_set_number 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 Signed-off-by: Dong Xu Wang --- qemu-option.c | 22 ++++++++++++++++++++++ qemu-option.h | 1 + 2 files changed, 23 insertions(+), 0 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 1303188..94557cf 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -695,6 +695,28 @@ int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val) return 0; } +int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val) +{ + QemuOpt *opt; + const QemuOptDesc *desc = opts->list->desc; + + opt = g_malloc0(sizeof(*opt)); + opt->desc = find_desc_by_name(desc, name); + if (!opt->desc && !opts_accepts_any(opts)) { + qerror_report(QERR_INVALID_PARAMETER, name); + g_free(opt); + return -1; + } + + opt->name = g_strdup(name); + opt->opts = opts; + opt->value.uint = val; + opt->str = g_strdup_printf("%" PRId64, val); + QTAILQ_INSERT_TAIL(&opts->head, opt, next); + + 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 b0f8d1e..002dd07 100644 --- a/qemu-option.h +++ b/qemu-option.h @@ -126,6 +126,7 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value); void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value, Error **errp); int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val); +int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t 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);