From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:37334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjASD-0001Hj-Sr for qemu-devel@nongnu.org; Thu, 13 Dec 2012 10:12:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TjARY-00060w-69 for qemu-devel@nongnu.org; Thu, 13 Dec 2012 10:12:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38195) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjARX-00060q-UG for qemu-devel@nongnu.org; Thu, 13 Dec 2012 10:11:24 -0500 From: Kevin Wolf Date: Thu, 13 Dec 2012 16:10:35 +0100 Message-Id: <1355411450-12761-29-git-send-email-kwolf@redhat.com> In-Reply-To: <1355411450-12761-1-git-send-email-kwolf@redhat.com> References: <1355411450-12761-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 28/43] create new function: qemu_opt_set_number List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Dong Xu Wang Signed-off-by: Dong Xu Wang Signed-off-by: Kevin Wolf --- 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); -- 1.7.6.5