From cc8a88c059fffe5e7834cb2bfc2bb7c932a67c77 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 1 Feb 2021 11:39:25 -0500 Subject: 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. --- service.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/service.c b/service.c index 6718b06..4ea9126 100644 --- a/service.c +++ b/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) { -- cgit 1.4.1 /a>/www/photo.causal.agency/2024-07-29 (unfollow)
Commit message (Expand)Author
2024-11-05Add a bunch of photosJune McEnroe
2024-10-12Publish "film review"June McEnroe
2024-10-12Add photos from October 6June McEnroe
2024-10-12Add photos from October 5June McEnroe
2024-10-09Add photos from October 1June McEnroe
2024-10-07Add photos from September 29June McEnroe
2024-10-07Add photos from September 28June McEnroe
2024-10-07Add photos from September 22June McEnroe
2024-09-25Add photos from September 15June McEnroe
2024-09-24Add photos from September 14June McEnroe
2024-09-24Add photos from September 12June McEnroe
2024-09-24Add photos from September 7June McEnroe
2024-09-24Allow not having descriptionsJune McEnroe
2024-09-23Automatically select the last used lens for a bodyJune McEnroe
2024-09-19Add photos from September 5June McEnroe
2024-09-15Add some more film stocks to the listJune McEnroe
2024-09-13Add photos from September 2June McEnroe
2024-09-13Add Fomapan 200 to films listJune McEnroe
2024-09-10Add August 29 picnic photosJune McEnroe
2024-09-08Apply some bold to trips renderingJune McEnroe
2024-09-08Render trips hopefully more efficientlyJune McEnroe
2024-09-08Allow removing bodies and lensesJune McEnroe
2024-09-08Limit body width so it looks less silly on desktopJune McEnroe
2024-09-07Handle no film being loadedJune McEnroe
2024-09-07Fancy up the text a littleJune McEnroe