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));
|
snprintf(buf, sizeof(buf), "%dms", (int)(interval.tv_nsec / 1000000));
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
int days = interval.tv_sec / (24 * 60 * 60);
|
int d = interval.tv_sec / (24 * 60 * 60);
|
||||||
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);
|
interval.tv_sec %= (60 * 60);
|
||||||
int mins = interval.tv_sec / 60;
|
int m = interval.tv_sec / 60;
|
||||||
interval.tv_sec %= 60;
|
interval.tv_sec %= 60;
|
||||||
int d, h, m, s;
|
int s = interval.tv_sec;
|
||||||
snprintf(
|
if (d) {
|
||||||
buf, sizeof(buf), "%n%dd %n%dh %n%dm %n%ds",
|
snprintf(buf, sizeof(buf), "%dd %dh %dm %ds", d, h, m, s);
|
||||||
&d, days, &h, hours, &m, mins, &s, (int)interval.tv_sec
|
} else if (h) {
|
||||||
);
|
snprintf(buf, sizeof(buf), "%dh %dm %ds", h, m, s);
|
||||||
if (days) return &buf[d];
|
} else if (m) {
|
||||||
if (hours) return &buf[h];
|
snprintf(buf, sizeof(buf), "%dm %ds", m, s);
|
||||||
if (mins) return &buf[m];
|
} else {
|
||||||
return &buf[s];
|
snprintf(buf, sizeof(buf), "%ds", s);
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void serviceStatus(struct Service *service) {
|
void serviceStatus(struct Service *service) {
|
||||||
|
Loading…
Reference in New Issue
Block a user