]> git.proxmox.com Git - qemu.git/blobdiff - cmd.c
osdep: introduce qemu_anon_ram_free to free qemu_anon_ram_alloc-ed memory
[qemu.git] / cmd.c
diff --git a/cmd.c b/cmd.c
index 75415d86a2866174ee5a9a4f66ac42f3472838e4..10a8688b2d25f47e4c552b4ec9ec675dc62b62f7 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -24,7 +24,8 @@
 #include <getopt.h>
 
 #include "cmd.h"
-#include "qemu-aio.h"
+#include "block/aio.h"
+#include "qemu/main-loop.h"
 
 #define _(x)   x       /* not gettext support yet */
 
@@ -146,7 +147,7 @@ static void prep_fetchline(void *opaque)
 {
     int *fetchable = opaque;
 
-    qemu_aio_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL, NULL, NULL);
+    qemu_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL);
     *fetchable= 1;
 }
 
@@ -193,12 +194,11 @@ void command_loop(void)
         if (!prompted) {
             printf("%s", get_prompt());
             fflush(stdout);
-            qemu_aio_set_fd_handler(STDIN_FILENO, prep_fetchline, NULL, NULL,
-                                    NULL, &fetchable);
+            qemu_set_fd_handler(STDIN_FILENO, prep_fetchline, NULL, &fetchable);
             prompted = 1;
         }
 
-        qemu_aio_wait();
+        main_loop_wait(false);
 
         if (!fetchable) {
             continue;
@@ -221,7 +221,7 @@ void command_loop(void)
         prompted = 0;
         fetchable = 0;
     }
-    qemu_aio_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL, NULL, NULL);
+    qemu_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL);
 }
 
 /* from libxcmd/input.c */
@@ -329,16 +329,21 @@ char **breakline(char *input, int *count)
     int c = 0;
     char *p;
     char **rval = calloc(sizeof(char *), 1);
+    char **tmp;
 
     while (rval && (p = qemu_strsep(&input, " ")) != NULL) {
         if (!*p) {
             continue;
         }
         c++;
-        rval = realloc(rval, sizeof(*rval) * (c + 1));
-        if (!rval) {
+        tmp = realloc(rval, sizeof(*rval) * (c + 1));
+        if (!tmp) {
+            free(rval);
+            rval = NULL;
             c = 0;
             break;
+        } else {
+            rval = tmp;
         }
         rval[c - 1] = p;
         rval[c] = NULL;
@@ -413,31 +418,37 @@ cvtstr(
        char            *str,
        size_t          size)
 {
-       const char      *fmt;
-       int             precise;
-
-       precise = ((double)value * 1000 == (double)(int)value * 1000);
+       char            *trim;
+       const char      *suffix;
 
        if (value >= EXABYTES(1)) {
-               fmt = precise ? "%.f EiB" : "%.3f EiB";
-               snprintf(str, size, fmt, TO_EXABYTES(value));
+               suffix = " EiB";
+               snprintf(str, size - 4, "%.3f", TO_EXABYTES(value));
        } else if (value >= PETABYTES(1)) {
-               fmt = precise ? "%.f PiB" : "%.3f PiB";
-               snprintf(str, size, fmt, TO_PETABYTES(value));
+               suffix = " PiB";
+               snprintf(str, size - 4, "%.3f", TO_PETABYTES(value));
        } else if (value >= TERABYTES(1)) {
-               fmt = precise ? "%.f TiB" : "%.3f TiB";
-               snprintf(str, size, fmt, TO_TERABYTES(value));
+               suffix = " TiB";
+               snprintf(str, size - 4, "%.3f", TO_TERABYTES(value));
        } else if (value >= GIGABYTES(1)) {
-               fmt = precise ? "%.f GiB" : "%.3f GiB";
-               snprintf(str, size, fmt, TO_GIGABYTES(value));
+               suffix = " GiB";
+               snprintf(str, size - 4, "%.3f", TO_GIGABYTES(value));
        } else if (value >= MEGABYTES(1)) {
-               fmt = precise ? "%.f MiB" : "%.3f MiB";
-               snprintf(str, size, fmt, TO_MEGABYTES(value));
+               suffix = " MiB";
+               snprintf(str, size - 4, "%.3f", TO_MEGABYTES(value));
        } else if (value >= KILOBYTES(1)) {
-               fmt = precise ? "%.f KiB" : "%.3f KiB";
-               snprintf(str, size, fmt, TO_KILOBYTES(value));
+               suffix = " KiB";
+               snprintf(str, size - 4, "%.3f", TO_KILOBYTES(value));
+       } else {
+               suffix = " bytes";
+               snprintf(str, size - 6, "%f", value);
+       }
+
+       trim = strstr(str, ".000");
+       if (trim) {
+               strcpy(trim, suffix);
        } else {
-               snprintf(str, size, "%f bytes", value);
+               strcat(str, suffix);
        }
 }