From 9ab2d3bb445c54f7d05a141b1b72e284a59f046c Mon Sep 17 00:00:00 2001 From: cheloha Date: Thu, 14 Sep 2023 18:32:03 +0000 Subject: [PATCH] sh(1), ksh(1): reimplement p_tv() with p_ts() p_tv() is identical to p_ts(). Better to not have two copies: in p_tv(), convert the timeval to a timespec and pass it to p_ts(). With input from tb@ and millert@. Thread: https://marc.info/?l=openbsd-tech&m=169448818503541&w=2 ok tb@ millert@ --- bin/ksh/c_sh.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/bin/ksh/c_sh.c b/bin/ksh/c_sh.c index 98f5e5e4f6d..32e692674ce 100644 --- a/bin/ksh/c_sh.c +++ b/bin/ksh/c_sh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_sh.c,v 1.64 2020/05/22 07:50:07 benno Exp $ */ +/* $OpenBSD: c_sh.c,v 1.65 2023/09/14 18:32:03 cheloha Exp $ */ /* * built-in Bourne commands @@ -680,14 +680,10 @@ static void p_tv(struct shf *shf, int posix, struct timeval *tv, int width, char *prefix, char *suffix) { - if (posix) - shf_fprintf(shf, "%s%*lld.%02ld%s", prefix ? prefix : "", - width, (long long)tv->tv_sec, tv->tv_usec / 10000, suffix); - else - shf_fprintf(shf, "%s%*lldm%02lld.%02lds%s", prefix ? prefix : "", - width, (long long)tv->tv_sec / 60, - (long long)tv->tv_sec % 60, - tv->tv_usec / 10000, suffix); + struct timespec ts; + + TIMEVAL_TO_TIMESPEC(tv, &ts); + p_ts(shf, posix, &ts, width, prefix, suffix); } static void -- 2.20.1