From c349e6f2e19281903fd8666cfeafe2f081fef66a Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 10 Oct 2018 05:28:06 -0500 Subject: Trivial speedup to format_iso_time(), teach parsetime() leading garbage != 0. --- lib/lib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/lib.c') diff --git a/lib/lib.c b/lib/lib.c index 9deadad9..03f0a24d 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -1404,8 +1404,11 @@ long long millitime(void) // Formats `ts` in ISO format ("2018-06-28 15:08:58.846386216 -0700"). char *format_iso_time(char *buf, size_t len, struct timespec *ts) { - strftime(buf, len, "%F %T", localtime(&(ts->tv_sec))); - sprintf(buf+strlen(buf), ".%09ld ", ts->tv_nsec); - strftime(buf+strlen(buf), len-strlen(buf), "%z", localtime(&(ts->tv_sec))); + char *s = buf; + + s += strftime(s, len, "%F %T", localtime(&(ts->tv_sec))); + s += sprintf(s, ".%09ld ", ts->tv_nsec); + s += strftime(s, len-strlen(buf), "%z", localtime(&(ts->tv_sec))); + return buf; } -- cgit v1.2.3