summaryrefslogtreecommitdiff
path: root/bin/dd
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2017-08-13 02:06:43 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2017-08-13 02:06:43 +0000
commit39201292e15e0c176feeeefc1c368beb1d94859d (patch)
tree155c9437567f5f07188dc611de5977d57d1897a7 /bin/dd
parentefb77c3247b8307ad69ce89704a6f4f9ec6384bb (diff)
convert gettimeofday to mono clock.
from Scott Cheloha
Diffstat (limited to 'bin/dd')
-rw-r--r--bin/dd/dd.c4
-rw-r--r--bin/dd/dd.h4
-rw-r--r--bin/dd/misc.c20
3 files changed, 14 insertions, 14 deletions
diff --git a/bin/dd/dd.c b/bin/dd/dd.c
index 2cbfe8679b2..1c20697f66e 100644
--- a/bin/dd/dd.c
+++ b/bin/dd/dd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dd.c,v 1.23 2015/10/09 01:37:06 deraadt Exp $ */
+/* $OpenBSD: dd.c,v 1.24 2017/08/13 02:06:42 tedu Exp $ */
/* $NetBSD: dd.c,v 1.6 1996/02/20 19:29:06 jtc Exp $ */
/*-
@@ -193,7 +193,7 @@ setup(void)
}
/* Statistics timestamp. */
- (void)gettimeofday(&st.startv, (struct timezone *)NULL);
+ clock_gettime(CLOCK_MONOTONIC, &st.start);
}
static void
diff --git a/bin/dd/dd.h b/bin/dd/dd.h
index 27f25a93358..a2c1c1bef24 100644
--- a/bin/dd/dd.h
+++ b/bin/dd/dd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dd.h,v 1.7 2016/08/16 16:44:55 krw Exp $ */
+/* $OpenBSD: dd.h,v 1.8 2017/08/13 02:06:42 tedu Exp $ */
/* $NetBSD: dd.h,v 1.4 1995/03/21 09:04:08 cgd Exp $ */
/*-
@@ -68,7 +68,7 @@ typedef struct {
size_t trunc; /* # of truncated records */
size_t swab; /* # of odd-length swab blocks */
off_t bytes; /* # of bytes written */
- struct timeval startv; /* start time of dd */
+ struct timespec start; /* start time of dd */
} STAT;
/* Flags (in ddflags). */
diff --git a/bin/dd/misc.c b/bin/dd/misc.c
index 6ab67411072..5758d25458f 100644
--- a/bin/dd/misc.c
+++ b/bin/dd/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.20 2016/08/25 05:25:21 tedu Exp $ */
+/* $OpenBSD: misc.c,v 1.21 2017/08/13 02:06:42 tedu Exp $ */
/* $NetBSD: misc.c,v 1.4 1995/03/21 09:04:10 cgd Exp $ */
/*-
@@ -52,20 +52,20 @@
void
summary(void)
{
- struct timeval nowtv;
+ struct timespec elapsed, now;
char buf[4][100];
struct iovec iov[4];
- double microsecs;
+ double nanosecs;
int i = 0;
if (ddflags & C_NOINFO)
return;
- (void)gettimeofday(&nowtv, (struct timezone *)NULL);
- timersub(&nowtv, &st.startv, &nowtv);
- microsecs = ((double)nowtv.tv_sec * 1000000) + nowtv.tv_usec;
- if (microsecs == 0)
- microsecs = 1;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ timespecsub(&now, &st.start, &elapsed);
+ nanosecs = ((double)elapsed.tv_sec * 1000000000) + elapsed.tv_nsec;
+ if (nanosecs == 0)
+ nanosecs = 1;
/* Use snprintf(3) so that we don't reenter stdio(3). */
(void)snprintf(buf[0], sizeof(buf[0]),
@@ -92,8 +92,8 @@ summary(void)
(void)snprintf(buf[3], sizeof(buf[3]),
"%lld bytes transferred in %lld.%03ld secs "
"(%0.0f bytes/sec)\n", (long long)st.bytes,
- (long long)nowtv.tv_sec, nowtv.tv_usec / 1000,
- ((double)st.bytes * 1000000) / microsecs);
+ (long long)elapsed.tv_sec, elapsed.tv_nsec / 1000000,
+ ((double)st.bytes * 1000000000) / nanosecs);
iov[i].iov_base = buf[3];
iov[i++].iov_len = strlen(buf[3]);
}