From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:36160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNNfy-00057g-9e for qemu-devel@nongnu.org; Sun, 14 Oct 2012 08:52:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TNNfx-0003ZN-8x for qemu-devel@nongnu.org; Sun, 14 Oct 2012 08:52:14 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:44927) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNNfx-0003XR-3Q for qemu-devel@nongnu.org; Sun, 14 Oct 2012 08:52:13 -0400 Received: by mail-pa0-f45.google.com with SMTP id fb10so3999127pad.4 for ; Sun, 14 Oct 2012 05:52:12 -0700 (PDT) Sender: Dong Xu Wang From: Dong Xu Wang Date: Sun, 14 Oct 2012 20:51:31 +0800 Message-Id: <1350219095-3378-7-git-send-email-wdongxu@linux.vnet.ibm.com> In-Reply-To: <1350219095-3378-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1350219095-3378-1-git-send-email-wdongxu@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH V3 06/10] create new function: qemu_opt_set_number List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, Dong Xu Wang 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); -- 1.7.1