From: Pierre Carrier <pierre@spotify.com>
To: linux-btrfs@vger.kernel.org
Cc: Pierre Carrier <pierre@spotify.com>
Subject: [PATCH 1/2] utils.c: fix sizes in B & malloc in pretty_sizes
Date: Mon, 9 Jul 2012 17:29:34 +0000 [thread overview]
Message-ID: <1341854974-14502-1-git-send-email-pierre@spotify.com> (raw)
In-Reply-To: <1341853347-11788-2-git-send-email-pierre@spotify.com>
Before, sizes below 1KB are still displayed in KB,
but without a unit.
Signed-off-by: Pierre Carrier <pierre@spotify.com>
diff --git a/utils.c b/utils.c
index aade9e2..937e763 100644
--- a/utils.c
+++ b/utils.c
@@ -1108,13 +1108,20 @@ char *pretty_sizes(u64 size)
size /= 1024;
num_divs++;
}
- if (num_divs == 0)
+ if (num_divs <= 1) {
num_divs = 1;
+ fraction = (float)fract_size;
+ } else
+ fraction = (float)fract_size / 1024;
+
if (num_divs > ARRAY_SIZE(size_strs))
return NULL;
- fraction = (float)fract_size / 1024;
+
pretty = malloc(pretty_len);
+ if (!pretty)
+ return NULL;
+
snprintf(pretty, pretty_len, "%.2f%s", fraction, size_strs[num_divs-1]);
return pretty;
}
--
1.7.11.1
next prev parent reply other threads:[~2012-07-09 17:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-09 17:02 [PATCH 0/2] Support for small units in display Pierre Carrier
2012-07-09 17:02 ` [PATCH 1/2] utils.c: fix sizes in B & malloc in pretty_sizes Pierre Carrier
2012-07-09 17:29 ` Pierre Carrier [this message]
2012-07-17 12:43 ` David Sterba
2012-07-09 17:02 ` [PATCH 2/2] utils.c: offer to limit divisions " Pierre Carrier
2012-07-09 17:30 ` Pierre Carrier
2012-07-17 12:58 ` David Sterba
2012-07-09 17:27 ` [PATCH 0/2] Support for small units in display Pierre Carrier
2012-07-17 12:34 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1341854974-14502-1-git-send-email-pierre@spotify.com \
--to=pierre@spotify.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).