repart: tweak byte value output

So far, when outputing information about copy progress we'd suppress the
digit after the dot if it is zero. That makes the progress bar a bit
"jumpy", because sometimes there are two more character cells used than
other times. Let's just always output one digit after the dot here
hence, to avoid this.
This commit is contained in:
Lennart Poettering
2025-09-19 16:46:07 +02:00
parent 222dcf3bc2
commit 2f5fb752a6
4 changed files with 39 additions and 27 deletions
+2 -1
View File
@@ -39,7 +39,8 @@ char* format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag) {
(t / table[i + 1].factor * 10 / table[n - 1].factor) % 10 :
(t * 10 / table[i].factor) % 10;
if (FLAGS_SET(flag, FORMAT_BYTES_BELOW_POINT) && remainder > 0)
if (FLAGS_SET(flag, FORMAT_BYTES_ALWAYS_POINT) ||
(FLAGS_SET(flag, FORMAT_BYTES_BELOW_POINT) && remainder > 0))
(void) snprintf(buf, l,
"%" PRIu64 ".%" PRIu64 "%s",
t / table[i].factor,
+6 -4
View File
@@ -64,9 +64,10 @@ assert_cc(sizeof(gid_t) == sizeof(uint32_t));
#endif
typedef enum {
FORMAT_BYTES_USE_IEC = 1 << 0,
FORMAT_BYTES_BELOW_POINT = 1 << 1,
FORMAT_BYTES_TRAILING_B = 1 << 2,
FORMAT_BYTES_USE_IEC = 1 << 0, /* use base 1024 rather than 1000 */
FORMAT_BYTES_BELOW_POINT = 1 << 1, /* show one digit after the point, if non-zero */
FORMAT_BYTES_ALWAYS_POINT = 1 << 2, /* show one digit after the point, always */
FORMAT_BYTES_TRAILING_B = 1 << 3, /* suffix the expression with a "B" for "bytes" */
} FormatBytesFlag;
#define FORMAT_BYTES_MAX 16U
@@ -82,6 +83,7 @@ static inline char* format_bytes(char *buf, size_t l, uint64_t t) {
* see C11 §6.5.2.5, and
* https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks */
#define FORMAT_BYTES(t) format_bytes((char[FORMAT_BYTES_MAX]){}, FORMAT_BYTES_MAX, t)
#define FORMAT_BYTES_FULL(t, flag) format_bytes_full((char[FORMAT_BYTES_MAX]){}, FORMAT_BYTES_MAX, t, flag)
#define FORMAT_BYTES_FULL(t, flags) format_bytes_full((char[FORMAT_BYTES_MAX]){}, FORMAT_BYTES_MAX, t, flags)
#define FORMAT_BYTES_WITH_POINT(t) format_bytes_full((char[FORMAT_BYTES_MAX]){}, FORMAT_BYTES_MAX, t, FORMAT_BYTES_USE_IEC|FORMAT_BYTES_ALWAYS_POINT|FORMAT_BYTES_TRAILING_B)
#define FORMAT_BYTES_CGROUP_PROTECTION(t) (t == CGROUP_LIMIT_MAX ? "infinity" : FORMAT_BYTES(t))