summaryrefslogtreecommitdiff
path: root/usr.bin/ssh
diff options
context:
space:
mode:
authorMarkus Friedl <markus@cvs.openbsd.org>2003-07-31 22:34:04 +0000
committerMarkus Friedl <markus@cvs.openbsd.org>2003-07-31 22:34:04 +0000
commit53a6b2d111f3675a3528163bb93035873cc6efe3 (patch)
tree7837cb15b8a3e3442c52b50bdf663ad8768b403f /usr.bin/ssh
parent71024192f8e6c068fce407d284f29caf19a22881 (diff)
print rate similar old version; round instead truncate;
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r--usr.bin/ssh/progressmeter.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/usr.bin/ssh/progressmeter.c b/usr.bin/ssh/progressmeter.c
index c7eb64be7aa..03bace47014 100644
--- a/usr.bin/ssh/progressmeter.c
+++ b/usr.bin/ssh/progressmeter.c
@@ -23,7 +23,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: progressmeter.c,v 1.12 2003/07/30 07:53:27 markus Exp $");
+RCSID("$OpenBSD: progressmeter.c,v 1.13 2003/07/31 22:34:03 markus Exp $");
#include "progressmeter.h"
#include "atomicio.h"
@@ -39,6 +39,7 @@ static int can_output(void);
/* formats and inserts the specified size into the given buffer */
static void format_size(char *, int, off_t);
+static void format_rate(char *, int, off_t);
/* updates the progressmeter to reflect the current state of the transfer */
void refresh_progress_meter(void);
@@ -56,6 +57,9 @@ static long stalled; /* how long we have been stalled */
static int bytes_per_second; /* current speed in bytes per second */
static int win_size; /* terminal window size */
+/* units for format_size */
+static const char unit[] = " KMGT";
+
static int
can_output(void)
{
@@ -63,13 +67,31 @@ can_output(void)
}
static void
+format_rate(char *buf, int size, off_t bytes)
+{
+ int i;
+
+ bytes *= 100;
+ for (i = 0; bytes >= 100*1000 && unit[i] != 'T'; i++)
+ bytes = (bytes + 512) / 1024;
+ if (i == 0) {
+ i++;
+ bytes = (bytes + 512) / 1024;
+ }
+ snprintf(buf, size, "%3lld.%1lld%c%s",
+ (long long) bytes / 100,
+ (long long) (bytes + 5) / 10 % 10,
+ unit[i],
+ i ? "B" : " ");
+}
+
+static void
format_size(char *buf, int size, off_t bytes)
{
- static const char unit[] = " KMGT";
int i;
for (i = 0; bytes >= 10000 && unit[i] != 'T'; i++)
- bytes /= 1024;
+ bytes = (bytes + 512) / 1024;
snprintf(buf, size, "%4lld%c%s",
(long long) bytes,
unit[i],
@@ -115,7 +137,7 @@ refresh_progress_meter(void)
/* filename */
buf[0] = '\0';
- file_len = win_size - 34;
+ file_len = win_size - 35;
if (file_len > 0) {
len = snprintf(buf, file_len, "\r%s", file);
for (i = len; i < file_len; i++ )
@@ -137,7 +159,7 @@ refresh_progress_meter(void)
strlcat(buf, " ", win_size);
/* bandwidth usage */
- format_size(buf + strlen(buf), win_size - strlen(buf),
+ format_rate(buf + strlen(buf), win_size - strlen(buf),
bytes_per_second);
strlcat(buf, "/s ", win_size);