qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 10/13] block: Simplify setting numeric options


From: Markus Armbruster
Subject: [Qemu-devel] [PATCH 10/13] block: Simplify setting numeric options
Date: Mon, 16 Feb 2015 15:44:22 +0100

Don't convert numbers to strings for use with qemu_opt_set(), simply
use qemu_opt_set_number() instead.

Signed-off-by: Markus Armbruster <address@hidden>
---
 blockdev.c |  4 +---
 vl.c       | 13 ++++++-------
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index f4c6e92..48c668c 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -180,7 +180,6 @@ QemuOpts *drive_add(BlockInterfaceType type, int index, 
const char *file,
                     const char *optstr)
 {
     QemuOpts *opts;
-    char buf[32];
 
     opts = drive_def(optstr);
     if (!opts) {
@@ -190,8 +189,7 @@ QemuOpts *drive_add(BlockInterfaceType type, int index, 
const char *file,
         qemu_opt_set(opts, "if", if_name[type], &error_abort);
     }
     if (index >= 0) {
-        snprintf(buf, sizeof(buf), "%d", index);
-        qemu_opt_set(opts, "index", buf, &error_abort);
+        qemu_opt_set_number(opts, "index", index, &error_abort);
     }
     if (file)
         qemu_opt_set(opts, "file", file, &error_abort);
diff --git a/vl.c b/vl.c
index a80d36f..dcb359a 100644
--- a/vl.c
+++ b/vl.c
@@ -2971,13 +2971,12 @@ int main(int argc, char **argv, char **envp)
                         exit(1);
                     }
                     if (hda_opts != NULL) {
-                        char num[16];
-                        snprintf(num, sizeof(num), "%d", cyls);
-                        qemu_opt_set(hda_opts, "cyls", num, &error_abort);
-                        snprintf(num, sizeof(num), "%d", heads);
-                        qemu_opt_set(hda_opts, "heads", num, &error_abort);
-                        snprintf(num, sizeof(num), "%d", secs);
-                        qemu_opt_set(hda_opts, "secs", num, &error_abort);
+                        qemu_opt_set_number(hda_opts, "cyls", cyls,
+                                            &error_abort);
+                        qemu_opt_set_number(hda_opts, "heads", heads,
+                                            &error_abort);
+                        qemu_opt_set_number(hda_opts, "secs", secs,
+                                            &error_abort);
                         if (translation == BIOS_ATA_TRANSLATION_LARGE) {
                             qemu_opt_set(hda_opts, "trans", "large",
                                          &error_abort);
-- 
1.9.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]