(size_trunc): added ability to show size in [G|g]bytes.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2011-08-10 10:23:46 +04:00
parent 12c893c73e
commit fc3bb20f09

View File

@ -332,10 +332,17 @@ size_trunc (uintmax_t size, gboolean use_si)
{
divisor = use_si ? 1000 : 1024;
xtra = use_si ? "k" : "K";
if (size / divisor > 999999999UL)
{
divisor = use_si ? (1000 * 1000) : (1024 * 1024);
xtra = use_si ? "m" : "M";
if (size / divisor > 999999999UL)
{
divisor = use_si ? (1000 * 1000 * 1000) : (1024 * 1024 * 1024);
xtra = use_si ? "g" : "G";
}
}
}
g_snprintf (x, sizeof (x), "%.0f%s", 1.0 * size / divisor, xtra);