From f227e9ec3eeb4e3575910a9c88d3ec7273443a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Fri, 25 Jul 2014 07:57:48 +0200 Subject: core: add terabyte unit for size displayed --- src/core/wee-string.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 6890810d6..a0edc34ac 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -2274,30 +2274,37 @@ string_iconv_fprintf (FILE *file, const char *data, ...) char * string_format_size (unsigned long long size) { - char *unit_name[] = { N_("bytes"), N_("KB"), N_("MB"), N_("GB") }; - char *unit_format[] = { "%.0f", "%.1f", "%.02f", "%.02f" }; - float unit_divide[] = { 1, 1024, 1024*1024, 1024*1024*1024 }; + char *unit_name[] = { "", N_("KB"), N_("MB"), N_("GB"), N_("TB") }; + char *unit_format[] = { "%.0f", "%.1f", "%.02f", "%.02f", "%.02f" }; + float unit_divide[] = { 1.0, 1000.0, 1000.0 * 1000.0, + 1000.0 * 1000.0 * 1000.0, + 1000.0 * 1000.0 * 1000.0 * 1000.0 }; char format_size[128], str_size[128]; int num_unit; + float size_float; str_size[0] = '\0'; - if (size < 1024*10) + if (size < 10L * 1000L) num_unit = 0; - else if (size < 1024*1024) + else if (size < 1000L * 1000L) num_unit = 1; - else if (size < 1024*1024*1024) + else if (size < 1000L * 1000L * 1000L) num_unit = 2; - else + else if (size < 1000L * 1000L * 1000L * 1000L) num_unit = 3; + else + num_unit = 4; snprintf (format_size, sizeof (format_size), "%s %%s", unit_format[num_unit]); + size_float = ((float)size) / ((float)(unit_divide[num_unit])); snprintf (str_size, sizeof (str_size), format_size, - ((float)size) / ((float)(unit_divide[num_unit])), - (size <= 1) ? _("byte") : _(unit_name[num_unit])); + size_float, + (num_unit == 0) ? + NG_("byte", "bytes", size_float) : _(unit_name[num_unit])); return strdup (str_size); } -- cgit v1.2.3