Remove use of "%n"
https://cvsweb.openbsd.org/src/lib/libc/stdio/vfprintf.c?rev=1.79&content-type=text/x-cvsweb-markup I think this is silly, as I've said elsewhere, and it's a shame because that was clearly the best way to write this. Oh well.
This commit is contained in:
parent
da4ccb18f4
commit
cc8a88c059
26
service.c
26
service.c
@ -133,21 +133,23 @@ static const char *humanize(struct timespec interval) {
|
||||
snprintf(buf, sizeof(buf), "%dms", (int)(interval.tv_nsec / 1000000));
|
||||
return buf;
|
||||
}
|
||||
int days = interval.tv_sec / (24 * 60 * 60);
|
||||
int d = interval.tv_sec / (24 * 60 * 60);
|
||||
interval.tv_sec %= (24 * 60 * 60);
|
||||
int hours = interval.tv_sec / (60 * 60);
|
||||
int h = interval.tv_sec / (60 * 60);
|
||||
interval.tv_sec %= (60 * 60);
|
||||
int mins = interval.tv_sec / 60;
|
||||
int m = interval.tv_sec / 60;
|
||||
interval.tv_sec %= 60;
|
||||
int d, h, m, s;
|
||||
snprintf(
|
||||
buf, sizeof(buf), "%n%dd %n%dh %n%dm %n%ds",
|
||||
&d, days, &h, hours, &m, mins, &s, (int)interval.tv_sec
|
||||
);
|
||||
if (days) return &buf[d];
|
||||
if (hours) return &buf[h];
|
||||
if (mins) return &buf[m];
|
||||
return &buf[s];
|
||||
int s = interval.tv_sec;
|
||||
if (d) {
|
||||
snprintf(buf, sizeof(buf), "%dd %dh %dm %ds", d, h, m, s);
|
||||
} else if (h) {
|
||||
snprintf(buf, sizeof(buf), "%dh %dm %ds", h, m, s);
|
||||
} else if (m) {
|
||||
snprintf(buf, sizeof(buf), "%dm %ds", m, s);
|
||||
} else {
|
||||
snprintf(buf, sizeof(buf), "%ds", s);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
void serviceStatus(struct Service *service) {
|
||||
|
Loading…
Reference in New Issue
Block a user