From patchwork Thu Oct 25 12:57:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 194181 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 5433E2C00A4 for ; Fri, 26 Oct 2012 01:27:03 +1100 (EST) Received: from localhost ([::1]:41288 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRN1O-0007hX-LN for incoming@patchwork.ozlabs.org; Thu, 25 Oct 2012 08:58:50 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRN0y-0007AH-8i for qemu-devel@nongnu.org; Thu, 25 Oct 2012 08:58:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TRN0s-0005PJ-C9 for qemu-devel@nongnu.org; Thu, 25 Oct 2012 08:58:24 -0400 Received: from mail-oa0-f45.google.com ([209.85.219.45]:55027) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRN0r-0005GV-3P for qemu-devel@nongnu.org; Thu, 25 Oct 2012 08:58:18 -0400 Received: by mail-oa0-f45.google.com with SMTP id i18so1476486oag.4 for ; Thu, 25 Oct 2012 05:58:16 -0700 (PDT) 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=hqvbgXYBQNUcxMxR00bs8RUdXe2g+1SgvDUCCNGUPrs=; b=dI206YOlAc07/b8d/Bc8I1Z1IOHbHLiqqSGmTFz1UK2D24lPKX2LGnAPxOuAb1NXhS pN8BTvIqzTcv9rsLalSTyTvhMeITFobTnSZMpjLWW3wOKi2+EG+HHJn9HZ4RRAhN6o7c q58i4vgtD14DamXDbGsFvv4VFFdFzxiRO+HldGX+Q75ct7eML51CmoOFDNODhDmo8fYk rUT8kTQJx9v3+9F88K9cMprDSoSGXbANmbWNvCsPiUB1n9NUxe0Lb3KFmNZbeo6fRdgr aA3OEFWhNSVJYa9GWjSbTEXmPVoF2tvZ7GQQJNZ2ptLCSUMm/z6eDJlbHAC2Q+vYM8H9 TAgw== Received: by 10.60.21.163 with SMTP id w3mr11977394oee.22.1351169896668; Thu, 25 Oct 2012 05:58:16 -0700 (PDT) Received: from localhost.localdomain ([202.108.130.138]) by mx.google.com with ESMTPS id k9sm6019404oeg.6.2012.10.25.05.58.13 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 25 Oct 2012 05:58:15 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Thu, 25 Oct 2012 20:57:24 +0800 Message-Id: <1351169848-28223-7-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1351169848-28223-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1351169848-28223-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.219.45 Cc: kwolf@redhat.com, Dong Xu Wang Subject: [Qemu-devel] [PATCH V4 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 | 24 ++++++++++++++++++++++++ qemu-option.h | 1 + 2 files changed, 25 insertions(+), 0 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index d7d5ea9..eeb2c9c 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -695,6 +695,30 @@ 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) +{ + char buffer[1024]; + QemuOpt *opt; + const QemuOptDesc *desc = opts->list->desc; + + snprintf(buffer, sizeof(buffer), "%" PRId64, val); + 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(buffer); + 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);