diff options
| author | Stefan Hajnoczi <stefanha@redhat.com> | 2017-05-18 10:16:38 +0100 |
|---|---|---|
| committer | Stefan Hajnoczi <stefanha@redhat.com> | 2017-05-18 13:36:15 +0100 |
| commit | 56821559f0ba682fe6b367815572e6f974d329ab (patch) | |
| tree | 75e93f8fc47707f61c1f6ad5ac45c7609c8da15a /qapi/string-output-visitor.c | |
| parent | 2ccbd47c1def618b31af1d88b550f6d2bdd15b0f (diff) | |
| parent | be9b23c4a539090da30b482015ee660850e8bb5f (diff) | |
| download | focaccia-qemu-56821559f0ba682fe6b367815572e6f974d329ab.tar.gz focaccia-qemu-56821559f0ba682fe6b367815572e6f974d329ab.zip | |
Merge remote-tracking branch 'dgilbert/tags/pull-hmp-20170517' into staging
HMP pull # gpg: Signature made Wed 17 May 2017 07:03:39 PM BST # gpg: using RSA key 0x0516331EBC5BFDE7 # gpg: Good signature from "Dr. David Alan Gilbert (RH2) <dgilbert@redhat.com>" # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 45F5 C71B 4A0C B7FB 977A 9FA9 0516 331E BC5B FDE7 * dgilbert/tags/pull-hmp-20170517: ramblock: add new hmp command "info ramblock" utils: provide size_to_str() ramblock: add RAMBLOCK_FOREACH() Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'qapi/string-output-visitor.c')
| -rw-r--r-- | qapi/string-output-visitor.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index 94ac8211d1..53c2175d81 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -211,10 +211,8 @@ static void print_type_size(Visitor *v, const char *name, uint64_t *obj, Error **errp) { StringOutputVisitor *sov = to_sov(v); - static const char suffixes[] = { 'B', 'K', 'M', 'G', 'T', 'P', 'E' }; - uint64_t div, val; - char *out; - int i; + uint64_t val; + char *out, *psize; if (!sov->human) { out = g_strdup_printf("%"PRIu64, *obj); @@ -223,19 +221,11 @@ static void print_type_size(Visitor *v, const char *name, uint64_t *obj, } val = *obj; - - /* The exponent (returned in i) minus one gives us - * floor(log2(val * 1024 / 1000). The correction makes us - * switch to the higher power when the integer part is >= 1000. - */ - frexp(val / (1000.0 / 1024.0), &i); - i = (i - 1) / 10; - assert(i < ARRAY_SIZE(suffixes)); - div = 1ULL << (i * 10); - - out = g_strdup_printf("%"PRIu64" (%0.3g %c%s)", val, - (double)val/div, suffixes[i], i ? "iB" : ""); + psize = size_to_str(val); + out = g_strdup_printf("%"PRIu64" (%s)", val, psize); string_output_set(sov, out); + + g_free(psize); } static void print_type_bool(Visitor *v, const char *name, bool *obj, |