aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-09-19 16:32:35 +0200
committerMattias Andrée <maandree@kth.se>2024-09-19 16:32:35 +0200
commit3a9bc8a4984a6c9e6b70c0f0a7187f06ad27ddca (patch)
tree940f5c388ddc79f2ebee79e911b6cfabc7e1cfd6
parentm (diff)
downloaddeadshred-3a9bc8a4984a6c9e6b70c0f0a7187f06ad27ddca.tar.gz
deadshred-3a9bc8a4984a6c9e6b70c0f0a7187f06ad27ddca.tar.bz2
deadshred-3a9bc8a4984a6c9e6b70c0f0a7187f06ad27ddca.tar.xz
Improve readability
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--deadshred.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/deadshred.c b/deadshred.c
index bcb1773..b849fc7 100644
--- a/deadshred.c
+++ b/deadshred.c
@@ -7,6 +7,12 @@
USAGE("[-o offset] [-l length | -e postend] device [< random-source]");
+#define NANOSECONDS(X) X##L
+#define MICROSECONDS(X) NANOSECONDS(X##000)
+#define MILLISECONDS(X) MICROSECONDS(X##000)
+#define CENTISECONDS(X) MILLISECONDS(X##0)
+#define DECISECONDS(X) CENTISECONDS(X##0)
+#define WHOLE_SECOND DECISECONDS(10)
enum direction {
FORWARDS = 0,
@@ -47,7 +53,6 @@ static struct timespec last_success = {-1, 0};
static struct timespec max_success = {-1, 0};
static struct timespec start_time;
-#define MILLISECONDS(X) X##000000L
static const struct timespec progress_print_interval = {0, MILLISECONDS(500)};
static const struct timespec poll_timeout = {0, MILLISECONDS(500)};
static int progress_print_sig_pipe[2];
@@ -262,7 +267,7 @@ unhumansize(const char *s, char flag)
static const char *
durationstr(const struct timespec *dur, char *buf, int second_decimals)
{
- uintmax_t ss, s, m, h, d, ss_div = UINTMAX_C(1000000000);
+ uintmax_t ss, s, m, h, d, ss_div = (uintmax_t)WHOLE_SECOND;
char *p;
const char *unit;
int i;
@@ -344,7 +349,7 @@ was_write_average_overrun(int i, const struct timespec *now, int seconds)
libsimple_difftimespec(&diff, now, &write_average_begin_times[i]);
if (diff.tv_sec >= seconds)
return 1;
- if (diff.tv_sec == seconds - 1 && diff.tv_nsec >= 900000000L)
+ if (diff.tv_sec == seconds - 1 && diff.tv_nsec >= DECISECONDS(9))
return 1;
return 0;
}
@@ -385,7 +390,7 @@ print_progress(int done, const struct timespec *now)
for (i = 0; i <= write_average_i; i++)
write_average_sum += write_average_amounts[i];
libsimple_difftimespec(&write_average_time, now, &write_average_begin_times[0]);
- if (write_average_time.tv_sec < 0 || (write_average_time.tv_sec == 0 && write_average_time.tv_nsec < 100000000L)) {
+ if (write_average_time.tv_sec < 0 || (write_average_time.tv_sec == 0 && write_average_time.tv_nsec < CENTISECONDS(10))) {
stpcpy(write_average_buf, "-");
} else if (write_average_sum == 0) {
stpcpy(write_average_buf, "0");
@@ -394,7 +399,7 @@ print_progress(int done, const struct timespec *now)
const char *units_small = "munpfazyrq";
int unit = -1;
write_average = (double)write_average_time.tv_nsec;
- write_average /= 1000000000L;
+ write_average /= WHOLE_SECOND;
write_average += (double)write_average_time.tv_sec;
write_average = (double)write_average_sum / write_average;
if (write_average < (double)0.01f) {