]> andersk Git - gssapi-openssh.git/blobdiff - openssh/progressmeter.c
fix typo on last checkin
[gssapi-openssh.git] / openssh / progressmeter.c
index c315464ee73aa7fbf1b19b64c9fc8ee1c52ae76f..93f5a3e622018b931c9690df07b208fa7832abf4 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: progressmeter.c,v 1.15 2003/08/31 12:14:22 markus Exp $");
+RCSID("$OpenBSD: progressmeter.c,v 1.22 2004/07/11 17:48:47 deraadt Exp $");
 
 #include "progressmeter.h"
 #include "atomicio.h"
@@ -48,15 +48,15 @@ void refresh_progress_meter(void);
 /* signal handler for updating the progress meter */
 static void update_progress_meter(int);
 
-static time_t start;           /* start progress */
-static time_t last_update;     /* last progress update */
-static char *file;             /* name of the file being transferred */
-static off_t end_pos;          /* ending position of transfer */
-static off_t cur_pos;          /* transfer position as of last refresh */
+static time_t start;           /* start progress */
+static time_t last_update;     /* last progress update */
+static char *file;             /* name of the file being transferred */
+static off_t end_pos;          /* ending position of transfer */
+static off_t cur_pos;          /* transfer position as of last refresh */
 static volatile off_t *counter;        /* progress counter */
-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 */
+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";
@@ -80,7 +80,7 @@ format_rate(char *buf, int size, off_t bytes)
                bytes = (bytes + 512) / 1024;
        }
        snprintf(buf, size, "%3lld.%1lld%c%s",
-           (int64_t) bytes / 100,
+           (int64_t) (bytes + 5) / 100,
            (int64_t) (bytes + 5) / 10 % 10,
            unit[i],
            i ? "B" : " ");
@@ -107,7 +107,7 @@ refresh_progress_meter(void)
        off_t transferred;
        double elapsed;
        int percent;
-       int bytes_left;
+       off_t bytes_left;
        int cur_speed;
        int hours, minutes, seconds;
        int i, len;
@@ -120,14 +120,18 @@ refresh_progress_meter(void)
 
        if (bytes_left > 0)
                elapsed = now - last_update;
-       else
+       else {
                elapsed = now - start;
+               /* Calculate true total speed when done */
+               transferred = end_pos;
+               bytes_per_second = 0;
+       }
 
        /* calculate speed */
        if (elapsed != 0)
                cur_speed = (transferred / elapsed);
        else
-               cur_speed = 0;
+               cur_speed = transferred;
 
 #define AGE_FACTOR 0.9
        if (bytes_per_second != 0) {
@@ -163,7 +167,7 @@ refresh_progress_meter(void)
 
        /* bandwidth usage */
        format_rate(buf + strlen(buf), win_size - strlen(buf),
-           bytes_per_second);
+           (off_t)bytes_per_second);
        strlcat(buf, "/s ", win_size);
 
        /* ETA */
@@ -200,7 +204,7 @@ refresh_progress_meter(void)
                        strlcat(buf, "    ", win_size);
        }
 
-       atomicio(vwrite, STDOUT_FILENO, buf, win_size);
+       atomicio(vwrite, STDOUT_FILENO, buf, win_size - 1);
        last_update = now;
 }
 
@@ -220,7 +224,7 @@ update_progress_meter(int ignore)
 }
 
 void
-start_progress_meter(char *f, off_t filesize, off_t *stat)
+start_progress_meter(char *f, off_t filesize, off_t *ctr)
 {
        struct winsize winsize;
 
@@ -228,7 +232,7 @@ start_progress_meter(char *f, off_t filesize, off_t *stat)
        file = f;
        end_pos = filesize;
        cur_pos = 0;
-       counter = stat;
+       counter = ctr;
        stalled = 0;
        bytes_per_second = 0;
 
This page took 0.042764 seconds and 4 git commands to generate.