Re: [PATCH 1/2] utils.c: fix sizes in B malloc in pretty_sizes
On Mon, Jul 09, 2012 at 05:29:34PM +, Pierre Carrier wrote: Before, sizes below 1KB are still displayed in KB, but without a unit. Does it matter when the only size below 1KB one can get is 0 ? Though for sake of consistency the B unit could be there in that case as well. -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/2] utils.c: fix sizes in B malloc in pretty_sizes
Before, sizes below 1KB where displayed in KB, but without a unit. Signed-off-by: Pierre Carrier pie...@spotify.com diff --git a/utils.c b/utils.c index aade9e2..dde0513 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 == 0) { 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 -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/2] utils.c: fix sizes in B malloc in pretty_sizes
Before, sizes below 1KB are still displayed in KB, but without a unit. Signed-off-by: Pierre Carrier pie...@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 -- To unsubscribe from this list: send the line unsubscribe linux-btrfs in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html