summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2014-07-25 07:57:48 +0200
committerSébastien Helleu <flashcode@flashtux.org>2014-07-25 07:57:48 +0200
commitf227e9ec3eeb4e3575910a9c88d3ec7273443a68 (patch)
tree3dd9f5f20665ac60bdab2bce261ef3a26139124b /src
parentb62705a29908b3d2038a91af6a312ddc8cba3988 (diff)
downloadweechat-f227e9ec3eeb4e3575910a9c88d3ec7273443a68.zip
core: add terabyte unit for size displayed
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-string.c25
1 files changed, 16 insertions, 9 deletions
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);
}