diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2003-08-13 17:48:47 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2003-08-13 17:48:47 +0000 |
commit | 4456f25e8fa584fa0a72e0a64961e384e5de587f (patch) | |
tree | d1d726f82f70ad2f444552d33880db11f748b8f1 | |
parent | 5b3c05637d41f25e3288680d5b2628d84b48397c (diff) | |
download | busybox-w32-4456f25e8fa584fa0a72e0a64961e384e5de587f.tar.gz busybox-w32-4456f25e8fa584fa0a72e0a64961e384e5de587f.tar.bz2 busybox-w32-4456f25e8fa584fa0a72e0a64961e384e5de587f.zip |
Rewrite timescmd() function to avoid the use of floating point and to
correct a bug in the seconds display where something like 65 seconds
would be output as "1m65.000000s".
-rw-r--r-- | shell/ash.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/shell/ash.c b/shell/ash.c index 74c33381a..547ad906b 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -12417,27 +12417,35 @@ findvar(struct var **vpp, const char *name) | |||
12417 | } | 12417 | } |
12418 | /* $NetBSD: setmode.c,v 1.29 2003/01/15 23:58:03 kleink Exp $ */ | 12418 | /* $NetBSD: setmode.c,v 1.29 2003/01/15 23:58:03 kleink Exp $ */ |
12419 | 12419 | ||
12420 | /* | ||
12421 | * Copyright (c) 1999 Herbert Xu <herbert@debian.org> | ||
12422 | * This code for the times builtin. | ||
12423 | */ | ||
12424 | |||
12425 | #include <sys/times.h> | 12420 | #include <sys/times.h> |
12426 | 12421 | ||
12427 | int timescmd(int ac, char **av) { | 12422 | static const unsigned char timescmd_str[] = { |
12423 | ' ', offsetof(struct tms, tms_utime), | ||
12424 | '\n', offsetof(struct tms, tms_stime), | ||
12425 | ' ', offsetof(struct tms, tms_cutime), | ||
12426 | '\n', offsetof(struct tms, tms_cstime), | ||
12427 | 0 | ||
12428 | }; | ||
12429 | |||
12430 | static int timescmd(int ac, char **av) | ||
12431 | { | ||
12432 | long int clk_tck, s, t; | ||
12433 | const unsigned char *p; | ||
12428 | struct tms buf; | 12434 | struct tms buf; |
12429 | long int clk_tck = sysconf(_SC_CLK_TCK); | ||
12430 | 12435 | ||
12436 | clk_tck = sysconf(_SC_CLK_TCK); | ||
12431 | times(&buf); | 12437 | times(&buf); |
12432 | out1fmt("%dm%fs %dm%fs\n%dm%fs %dm%fs\n", | 12438 | |
12433 | (int) (buf.tms_utime / clk_tck / 60), | 12439 | p = timescmd_str; |
12434 | ((double) buf.tms_utime) / clk_tck, | 12440 | do { |
12435 | (int) (buf.tms_stime / clk_tck / 60), | 12441 | t = *(clock_t *)(((char *) &buf) + p[1]); |
12436 | ((double) buf.tms_stime) / clk_tck, | 12442 | s = t / clk_tck; |
12437 | (int) (buf.tms_cutime / clk_tck / 60), | 12443 | out1fmt("%ldm%ld.%.3lds%c", |
12438 | ((double) buf.tms_cutime) / clk_tck, | 12444 | s/60, s%60, |
12439 | (int) (buf.tms_cstime / clk_tck / 60), | 12445 | ((t - s * clk_tck) * 1000) / clk_tck, |
12440 | ((double) buf.tms_cstime) / clk_tck); | 12446 | p[0]); |
12447 | } while (*(p += 2)); | ||
12448 | |||
12441 | return 0; | 12449 | return 0; |
12442 | } | 12450 | } |
12443 | 12451 | ||