diff options
-rw-r--r-- | misc.c | 13 | ||||
-rw-r--r-- | misc.h | 3 | ||||
-rw-r--r-- | progressmeter.c | 13 |
3 files changed, 20 insertions, 9 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.c,v 1.101 2016/01/20 09:22:39 dtucker Exp $ */ | 1 | /* $OpenBSD: misc.c,v 1.102 2016/03/02 22:42:40 dtucker Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. |
@@ -909,6 +909,17 @@ monotime(void) | |||
909 | return time(NULL); | 909 | return time(NULL); |
910 | } | 910 | } |
911 | 911 | ||
912 | double | ||
913 | monotime_double(void) | ||
914 | { | ||
915 | struct timespec ts; | ||
916 | |||
917 | if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) | ||
918 | fatal("clock_gettime: %s", strerror(errno)); | ||
919 | |||
920 | return (ts.tv_sec + (double)ts.tv_nsec / 1000000000); | ||
921 | } | ||
922 | |||
912 | void | 923 | void |
913 | bandwidth_limit_init(struct bwlimit *bw, u_int64_t kbps, size_t buflen) | 924 | bandwidth_limit_init(struct bwlimit *bw, u_int64_t kbps, size_t buflen) |
914 | { | 925 | { |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.h,v 1.54 2014/07/15 15:54:14 millert Exp $ */ | 1 | /* $OpenBSD: misc.h,v 1.55 2016/03/02 22:42:40 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
@@ -55,6 +55,7 @@ void sanitise_stdfd(void); | |||
55 | void ms_subtract_diff(struct timeval *, int *); | 55 | void ms_subtract_diff(struct timeval *, int *); |
56 | void ms_to_timeval(struct timeval *, int); | 56 | void ms_to_timeval(struct timeval *, int); |
57 | time_t monotime(void); | 57 | time_t monotime(void); |
58 | double monotime_double(void); | ||
58 | void lowercase(char *s); | 59 | void lowercase(char *s); |
59 | int unix_listener(const char *, int, int); | 60 | int unix_listener(const char *, int, int); |
60 | 61 | ||
diff --git a/progressmeter.c b/progressmeter.c index 319b7470a..3a455408c 100644 --- a/progressmeter.c +++ b/progressmeter.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: progressmeter.c,v 1.41 2015/01/14 13:54:13 djm Exp $ */ | 1 | /* $OpenBSD: progressmeter.c,v 1.42 2016/03/02 22:42:40 dtucker Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2003 Nils Nordman. All rights reserved. | 3 | * Copyright (c) 2003 Nils Nordman. All rights reserved. |
4 | * | 4 | * |
@@ -63,8 +63,8 @@ void refresh_progress_meter(void); | |||
63 | /* signal handler for updating the progress meter */ | 63 | /* signal handler for updating the progress meter */ |
64 | static void update_progress_meter(int); | 64 | static void update_progress_meter(int); |
65 | 65 | ||
66 | static time_t start; /* start progress */ | 66 | static double start; /* start progress */ |
67 | static time_t last_update; /* last progress update */ | 67 | static double last_update; /* last progress update */ |
68 | static const char *file; /* name of the file being transferred */ | 68 | static const char *file; /* name of the file being transferred */ |
69 | static off_t start_pos; /* initial position of transfer */ | 69 | static off_t start_pos; /* initial position of transfer */ |
70 | static off_t end_pos; /* ending position of transfer */ | 70 | static off_t end_pos; /* ending position of transfer */ |
@@ -120,9 +120,8 @@ void | |||
120 | refresh_progress_meter(void) | 120 | refresh_progress_meter(void) |
121 | { | 121 | { |
122 | char buf[MAX_WINSIZE + 1]; | 122 | char buf[MAX_WINSIZE + 1]; |
123 | time_t now; | ||
124 | off_t transferred; | 123 | off_t transferred; |
125 | double elapsed; | 124 | double elapsed, now; |
126 | int percent; | 125 | int percent; |
127 | off_t bytes_left; | 126 | off_t bytes_left; |
128 | int cur_speed; | 127 | int cur_speed; |
@@ -132,7 +131,7 @@ refresh_progress_meter(void) | |||
132 | 131 | ||
133 | transferred = *counter - (cur_pos ? cur_pos : start_pos); | 132 | transferred = *counter - (cur_pos ? cur_pos : start_pos); |
134 | cur_pos = *counter; | 133 | cur_pos = *counter; |
135 | now = monotime(); | 134 | now = monotime_double(); |
136 | bytes_left = end_pos - cur_pos; | 135 | bytes_left = end_pos - cur_pos; |
137 | 136 | ||
138 | if (bytes_left > 0) | 137 | if (bytes_left > 0) |
@@ -250,7 +249,7 @@ update_progress_meter(int ignore) | |||
250 | void | 249 | void |
251 | start_progress_meter(const char *f, off_t filesize, off_t *ctr) | 250 | start_progress_meter(const char *f, off_t filesize, off_t *ctr) |
252 | { | 251 | { |
253 | start = last_update = monotime(); | 252 | start = last_update = monotime_double(); |
254 | file = f; | 253 | file = f; |
255 | start_pos = *ctr; | 254 | start_pos = *ctr; |
256 | end_pos = filesize; | 255 | end_pos = filesize; |