summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJia Tan <jiat0218@gmail.com>2022-11-07 16:24:14 +0200
committerLasse Collin <lasse.collin@tukaani.org>2022-11-11 13:41:43 +0200
commitd4674dfbb7d1df1feb841f5dbce6ae1f0b026879 (patch)
tree22aefcdbc01d9e2a24053a6bbc03550ec45aa6a3
parent4ed56d32a91ff8ff21c71db4082a54a72ae08b3d (diff)
downloadxz-d4674dfbb7d1df1feb841f5dbce6ae1f0b026879.tar.gz
xz: Avoid a compiler warning in progress_speed() in message.c.
This should be smaller too since it avoids the string constants.
-rw-r--r--src/xz/message.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/xz/message.c b/src/xz/message.c
index aa915d2..91e0de4 100644
--- a/src/xz/message.c
+++ b/src/xz/message.c
@@ -355,11 +355,8 @@ progress_speed(uint64_t uncompressed_pos, uint64_t elapsed)
if (elapsed < 3000)
return "";
- static const char unit[][8] = {
- "KiB/s",
- "MiB/s",
- "GiB/s",
- };
+ // The first character of KiB/s, MiB/s, or GiB/s:
+ static const char unit[] = { 'K', 'M', 'G' };
size_t unit_index = 0;
@@ -381,7 +378,7 @@ progress_speed(uint64_t uncompressed_pos, uint64_t elapsed)
// - 999 KiB/s
// Use big enough buffer to hold e.g. a multibyte decimal point.
static char buf[16];
- snprintf(buf, sizeof(buf), "%.*f %s",
+ snprintf(buf, sizeof(buf), "%.*f %ciB/s",
speed > 9.9 ? 0 : 1, speed, unit[unit_index]);
return buf;
}