Re: ksh(1): implement p_tv() with p_ts()
On Tue, 12 Sep 2023 07:49:27 +0200, Theo Buehler wrote: > While this looks like an improvement to me, this uses a new non-portable > construct in ksh. I don't know how much we care. I don't think we care. If someone wants to ports our ksh it is easy enough to supply TIMEVAL_TO_TIMESPEC if necessary. - todd
Re: ksh(1): implement p_tv() with p_ts()
On Mon, 11 Sep 2023 22:10:49 -0500, Scott Cheloha wrote: > p_tv() is identical to p_ts() in every way except for the subsecond > conversion constants. > > Better to write p_ts() once: in p_tv(), convert from timeval to > timespec and call p_ts(). OK millert@ - todd
Re: ksh(1): implement p_tv() with p_ts()
On Mon, Sep 11, 2023 at 10:10:49PM -0500, Scott Cheloha wrote: > p_tv() is identical to p_ts() in every way except for the subsecond > conversion constants. > > Better to write p_ts() once: in p_tv(), convert from timeval to > timespec and call p_ts(). While this looks like an improvement to me, this uses a new non-portable construct in ksh. I don't know how much we care. > > Index: c_sh.c > === > RCS file: /cvs/src/bin/ksh/c_sh.c,v > retrieving revision 1.64 > diff -u -p -r1.64 c_sh.c > --- c_sh.c22 May 2020 07:50:07 - 1.64 > +++ c_sh.c12 Sep 2023 03:07:16 - > @@ -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 / 1, 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 / 1, suffix); > + struct timespec ts; > + > + TIMEVAL_TO_TIMESPEC(tv, &ts); > + p_ts(shf, posix, &ts, width, prefix, suffix); > } > > static void >
ksh(1): implement p_tv() with p_ts()
p_tv() is identical to p_ts() in every way except for the subsecond conversion constants. Better to write p_ts() once: in p_tv(), convert from timeval to timespec and call p_ts(). ok? Index: c_sh.c === RCS file: /cvs/src/bin/ksh/c_sh.c,v retrieving revision 1.64 diff -u -p -r1.64 c_sh.c --- c_sh.c 22 May 2020 07:50:07 - 1.64 +++ c_sh.c 12 Sep 2023 03:07:16 - @@ -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 / 1, 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 / 1, suffix); + struct timespec ts; + + TIMEVAL_TO_TIMESPEC(tv, &ts); + p_ts(shf, posix, &ts, width, prefix, suffix); } static void