summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2017-09-10 07:29:40 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2017-09-10 07:29:40 +0000
commitb85c4b98ab3c0eba0be94fb0d56d22be0a935413 (patch)
treeab550d05564beb9d8626df7100c64a72296d6a3e /usr.bin
parent46c258727e1a85925e4c7f4a88e2bf3ddd77c667 (diff)
Use monotonic clock for statistics display. From Scott Cheloha.
ok dlg
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tftp/tftp.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/usr.bin/tftp/tftp.c b/usr.bin/tftp/tftp.c
index 77d0858c867..265f51efa66 100644
--- a/usr.bin/tftp/tftp.c
+++ b/usr.bin/tftp/tftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tftp.c,v 1.24 2014/10/21 06:15:16 dlg Exp $ */
+/* $OpenBSD: tftp.c,v 1.25 2017/09/10 07:29:39 tb Exp $ */
/* $NetBSD: tftp.c,v 1.5 1995/04/29 05:55:25 cgd Exp $ */
/*
@@ -52,6 +52,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include <netdb.h>
@@ -83,8 +84,8 @@ extern int opt_tsize;
extern int opt_tout;
extern int opt_blksize;
-struct timeval tstart;
-struct timeval tstop;
+struct timespec tstart;
+struct timespec tstop;
unsigned int segment_size = SEGSIZE;
unsigned int packet_size = SEGSIZE + 4;
@@ -548,13 +549,13 @@ tpacket(const char *s, struct tftphdr *tp, int n)
static void
startclock(void)
{
- (void)gettimeofday(&tstart, NULL);
+ clock_gettime(CLOCK_MONOTONIC, &tstart);
}
static void
stopclock(void)
{
- (void)gettimeofday(&tstop, NULL);
+ clock_gettime(CLOCK_MONOTONIC, &tstop);
}
static void
@@ -563,8 +564,8 @@ printstats(const char *direction, unsigned long amount)
double delta;
/* compute delta in 1/10's second units */
- delta = ((tstop.tv_sec * 10.) + (tstop.tv_usec / 100000)) -
- ((tstart.tv_sec * 10.) + (tstart.tv_usec / 100000));
+ delta = ((tstop.tv_sec * 10.) + (tstop.tv_nsec / 100000000)) -
+ ((tstart.tv_sec * 10.) + (tstart.tv_nsec / 100000000));
delta = delta / 10.; /* back to seconds */
printf("%s %lu bytes in %.1f seconds", direction, amount, delta);
if (verbose)