diff options
author | phk <phk@FreeBSD.org> | 1996-11-13 20:00:03 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 1996-11-13 20:00:03 +0000 |
commit | 6c0fd53b323fe1e401dc8c67516a053bfe61f962 (patch) | |
tree | 53fc828f0ad161e700a6fc8fe723a969aade6a4b /bin/dd/misc.c | |
parent | 46e1202181d505ac01d3b6baa6922896edbfca8a (diff) | |
download | FreeBSD-src-6c0fd53b323fe1e401dc8c67516a053bfe61f962.zip FreeBSD-src-6c0fd53b323fe1e401dc8c67516a053bfe61f962.tar.gz |
Bruce says: "You have been programming in the kernel for too long :-)."
and he's right ... I forgot about this floating point stuff you can
use in user-land :-)
Increase precision of duration to microseconds.
No heuristics to avoid overflow in calculation needed - just depend
on DBL_MAX being a bit larger than LONG_MAX.
Use double instead of `struct timeval' in dd.h so that everything
doesn't have to include <sys/time.h>.
Fixed style bugs in recent and old FreeBSD changes.
Reviewed by: phk
Submitted by: bde
Diffstat (limited to 'bin/dd/misc.c')
-rw-r--r-- | bin/dd/misc.c | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/bin/dd/misc.c b/bin/dd/misc.c index 7e6932f..9b577ef 100644 --- a/bin/dd/misc.c +++ b/bin/dd/misc.c @@ -34,7 +34,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: misc.c,v 1.2 1994/09/24 02:55:01 davidg Exp $ + * $Id: misc.c,v 1.3 1996/11/12 23:09:15 phk Exp $ */ #ifndef lint @@ -42,6 +42,7 @@ static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94"; #endif /* not lint */ #include <sys/types.h> +#include <sys/time.h> #include <err.h> #include <stdio.h> @@ -49,7 +50,6 @@ static char sccsid[] = "@(#)misc.c 8.3 (Berkeley) 4/2/94"; #include <string.h> #include <time.h> #include <unistd.h> -#include <sys/time.h> #include "dd.h" #include "extern.h" @@ -58,22 +58,13 @@ void summary() { struct timeval tv; - long msec; + double secs; char buf[100]; - (void)gettimeofday(&tv, 0); - tv.tv_sec -= st.start.tv_sec; - tv.tv_usec -= st.start.tv_usec; - if (tv.tv_usec < 0) { - tv.tv_usec += 1000000; - tv.tv_sec--; - } - - msec = tv.tv_sec * 1000; - msec += tv.tv_usec / 1000; - - if (msec == 0) - msec = 1; + (void)gettimeofday(&tv, (struct timezone *)NULL); + secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start; + if (secs < 1e-6) + secs = 1e-6; /* Use snprintf(3) so that we don't reenter stdio(3). */ (void)snprintf(buf, sizeof(buf), "%u+%u records in\n%u+%u records out\n", @@ -89,15 +80,9 @@ summary() st.trunc, (st.trunc == 1) ? "block" : "blocks"); (void)write(STDERR_FILENO, buf, strlen(buf)); } - if (msec > 1000000) { - (void)snprintf(buf, sizeof(buf), - "%u bytes transferred in %u.%03d secs (%u bytes/sec)\n", - st.bytes, tv.tv_sec, 0, st.bytes / tv.tv_sec); - } else { - (void)snprintf(buf, sizeof(buf), - "%u bytes transferred in %u.%03d secs (%u bytes/sec)\n", - st.bytes, msec/1000, msec%1000, st.bytes*1000 / msec); - } + (void)snprintf(buf, sizeof(buf), + "%u bytes transferred in %.6f secs (%.0f bytes/sec)\n", + st.bytes, secs, st.bytes / secs); (void)write(STDERR_FILENO, buf, strlen(buf)); } |