X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=cmd.c;h=10a8688b2d25f47e4c552b4ec9ec675dc62b62f7;hb=be17f18b8cd438be7f8f65000c0baecdd5b34634;hp=7ffbb7140649116e68cb1fbe79ad89850e791074;hpb=d6a6922f3bebbf95e2d5194a9cb8a21e3d5ddfdd;p=qemu.git diff --git a/cmd.c b/cmd.c index 7ffbb7140..10a8688b2 100644 --- a/cmd.c +++ b/cmd.c @@ -24,8 +24,8 @@ #include #include "cmd.h" -#include "qemu-aio.h" -#include "main-loop.h" +#include "block/aio.h" +#include "qemu/main-loop.h" #define _(x) x /* not gettext support yet */ @@ -418,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); } }