diff options
author | Rob Landley <rob@landley.net> | 2018-10-10 05:28:06 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2018-10-10 05:28:06 -0500 |
commit | c349e6f2e19281903fd8666cfeafe2f081fef66a (patch) | |
tree | 951c3a17dc03f14902a9d73c8435ec93d0de3cd0 | |
parent | c276b8a8c2a5181558b976b9cb1d60a0180d560e (diff) | |
download | toybox-c349e6f2e19281903fd8666cfeafe2f081fef66a.tar.gz |
Trivial speedup to format_iso_time(), teach parsetime() leading garbage != 0.
-rw-r--r-- | lib/lib.c | 9 | ||||
-rw-r--r-- | lib/xwrap.c | 1 |
2 files changed, 7 insertions, 3 deletions
@@ -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; } diff --git a/lib/xwrap.c b/lib/xwrap.c index 7276151f..2c3b6041 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -795,6 +795,7 @@ long xparsetime(char *arg, long units, long *fraction) long l; char *end; + if (*arg != '.' && !isdigit(*arg)) error_exit("bad %s", arg); if (CFG_TOYBOX_FLOAT) d = strtod(arg, &end); else l = strtoul(arg, &end, 10); |