]> git.ipfire.org Git - pakfire.git/commitdiff
util: format_size: Add decimal points where appropriate
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 11 Apr 2021 17:22:37 +0000 (17:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 11 Apr 2021 17:22:37 +0000 (17:22 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/util.c

index 6d199e1badb6ca1eb49f5500c9525f4eac475a0b..36cc21e1f5ea02a71827997372dc99c11bd4592a 100644 (file)
@@ -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