[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH V3 06/10] create new function: qemu_opt_set_number
From: |
Dong Xu Wang |
Subject: |
[Qemu-devel] [PATCH V3 06/10] create new function: qemu_opt_set_number |
Date: |
Sun, 14 Oct 2012 20:51:31 +0800 |
Signed-off-by: Dong Xu Wang <address@hidden>
---
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
- [Qemu-devel] [PATCH V3 00/10] replace QEMUOptionParameter with QemuOpts parser, Dong Xu Wang, 2012/10/14
- [Qemu-devel] [PATCH V3 01/10] qemu-option: opt_set(): split it up into more functions, Dong Xu Wang, 2012/10/14
- [Qemu-devel] [PATCH V3 07/10] add def_value and use it in qemu_opts_print., Dong Xu Wang, 2012/10/14
- [Qemu-devel] [PATCH V3 09/10] Use QemuOpts support in block layer, Dong Xu Wang, 2012/10/14
- [Qemu-devel] [PATCH V3 06/10] create new function: qemu_opt_set_number,
Dong Xu Wang <=
- [Qemu-devel] [PATCH V3 03/10] qemu-option: qemu_opt_set_bool(): fix code duplication, Dong Xu Wang, 2012/10/14
- [Qemu-devel] [PATCH V3 10/10] remove QEMUOptionParameter related functions and struct, Dong Xu Wang, 2012/10/14
- [Qemu-devel] [PATCH V3 08/10] Create four opts list related functions, Dong Xu Wang, 2012/10/14
- [Qemu-devel] [PATCH V3 04/10] introduce qemu_opts_create_nofail function, Dong Xu Wang, 2012/10/14
- [Qemu-devel] [PATCH V3 02/10] qemu-option: qemu_opts_validate(): fix duplicated code, Dong Xu Wang, 2012/10/14
- [Qemu-devel] [PATCH V3 05/10] use qemu_opts_create_nofail, Dong Xu Wang, 2012/10/14