1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix very silly bug in times builtin (re: 65d363fd)

Well, that's what I get for backporting code without properly
checking it over. There was an elementary math error in how the
times builtin calculated seconds:
	utime_sec = utime - utime_min;
which could cause output such as "1m98.38s" or "3m234.77s".

src/cmd/ksh93/bltins/misc.c: b_times():
- Use fmod(), i.e. floating point modulus, to calculate seconds.
This commit is contained in:
Martijn Dekker 2020-06-24 07:47:57 +02:00
parent d8fe061f4c
commit 57ff4676eb

View file

@ -498,19 +498,19 @@ int b_times(int argc, char *argv[], Shbltin_t *context)
/* First line: user and system times used by the shell */
utime = (double)cpu_times.tms_utime / shp->gd->lim.clk_tck;
utime_min = floor(utime / 60);
utime_sec = utime - utime_min;
utime_sec = fmod(utime, 60);
stime = (double)cpu_times.tms_stime / shp->gd->lim.clk_tck;
stime_min = floor(stime / 60);
stime_sec = stime - stime_min;
stime_sec = fmod(stime, 60);
sfprintf(sfstdout, "%dm%.2fs %dm%.2fs\n", (int)utime_min, utime_sec, (int)stime_min, stime_sec);
/* Second line: same for the shell's child processes */
utime = (double)cpu_times.tms_cutime / shp->gd->lim.clk_tck;
utime_min = floor(utime / 60);
utime_sec = utime - utime_min;
utime_sec = fmod(utime, 60);
stime = (double)cpu_times.tms_cstime / shp->gd->lim.clk_tck;
stime_min = floor(stime / 60);
stime_sec = stime - stime_min;
stime_sec = fmod(stime, 60);
sfprintf(sfstdout, "%dm%.2fs %dm%.2fs\n", (int)utime_min, utime_sec, (int)stime_min, stime_sec);
return(0);