From: Michael Tremer Date: Sun, 11 Apr 2021 17:22:37 +0000 (+0000) Subject: util: format_size: Add decimal points where appropriate X-Git-Tag: 0.9.28~1285^2~369 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df56e4ef95a94d277b598267c4382aee6f0c1ddb;p=pakfire.git util: format_size: Add decimal points where appropriate Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index 6d199e1ba..36cc21e1f 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -227,7 +227,14 @@ char** pakfire_split_string(const char* s, char delim) { } int pakfire_format_size(char* dst, size_t length, double value) { - const char* units[] = {" ", "k", "M", "G", "T", NULL}; + const char* units[] = { + "%4.0f ", + "%4.0fk", + "%4.1fM", + "%4.1fG", + "%4.1fT", + NULL + }; const char** unit = units; while (*(unit + 1) && value >= 1024.0) { @@ -235,7 +242,10 @@ int pakfire_format_size(char* dst, size_t length, double value) { unit++; } - return snprintf(dst, length, "%.0f%s", round(value), *unit); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" + return snprintf(dst, length, *unit, round(value)); +#pragma GCC diagnostic pop } #pragma GCC diagnostic push