Deleted Added
full compact
progressmeter.c (126274) progressmeter.c (137015)
1/*
2 * Copyright (c) 2003 Nils Nordman. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 9 unchanged lines hidden (view full) ---

18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include "includes.h"
1/*
2 * Copyright (c) 2003 Nils Nordman. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 9 unchanged lines hidden (view full) ---

18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include "includes.h"
26RCSID("$OpenBSD: progressmeter.c,v 1.19 2004/02/05 15:33:33 markus Exp $");
26RCSID("$OpenBSD: progressmeter.c,v 1.22 2004/07/11 17:48:47 deraadt Exp $");
27
28#include "progressmeter.h"
29#include "atomicio.h"
30#include "misc.h"
31
32#define DEFAULT_WINSIZE 80
33#define MAX_WINSIZE 512
34#define PADDING 1 /* padding between the progress indicators */

--- 8 unchanged lines hidden (view full) ---

43static void format_rate(char *, int, off_t);
44
45/* updates the progressmeter to reflect the current state of the transfer */
46void refresh_progress_meter(void);
47
48/* signal handler for updating the progress meter */
49static void update_progress_meter(int);
50
27
28#include "progressmeter.h"
29#include "atomicio.h"
30#include "misc.h"
31
32#define DEFAULT_WINSIZE 80
33#define MAX_WINSIZE 512
34#define PADDING 1 /* padding between the progress indicators */

--- 8 unchanged lines hidden (view full) ---

43static void format_rate(char *, int, off_t);
44
45/* updates the progressmeter to reflect the current state of the transfer */
46void refresh_progress_meter(void);
47
48/* signal handler for updating the progress meter */
49static void update_progress_meter(int);
50
51static time_t start; /* start progress */
52static time_t last_update; /* last progress update */
53static char *file; /* name of the file being transferred */
54static off_t end_pos; /* ending position of transfer */
55static off_t cur_pos; /* transfer position as of last refresh */
51static time_t start; /* start progress */
52static time_t last_update; /* last progress update */
53static char *file; /* name of the file being transferred */
54static off_t end_pos; /* ending position of transfer */
55static off_t cur_pos; /* transfer position as of last refresh */
56static volatile off_t *counter; /* progress counter */
56static volatile off_t *counter; /* progress counter */
57static long stalled; /* how long we have been stalled */
58static int bytes_per_second; /* current speed in bytes per second */
59static int win_size; /* terminal window size */
57static long stalled; /* how long we have been stalled */
58static int bytes_per_second; /* current speed in bytes per second */
59static int win_size; /* terminal window size */
60
61/* units for format_size */
62static const char unit[] = " KMGT";
63
64static int
65can_output(void)
66{
67 return (getpgrp() == tcgetpgrp(STDOUT_FILENO));

--- 94 unchanged lines hidden (view full) ---

162
163 /* amount transferred */
164 format_size(buf + strlen(buf), win_size - strlen(buf),
165 cur_pos);
166 strlcat(buf, " ", win_size);
167
168 /* bandwidth usage */
169 format_rate(buf + strlen(buf), win_size - strlen(buf),
60
61/* units for format_size */
62static const char unit[] = " KMGT";
63
64static int
65can_output(void)
66{
67 return (getpgrp() == tcgetpgrp(STDOUT_FILENO));

--- 94 unchanged lines hidden (view full) ---

162
163 /* amount transferred */
164 format_size(buf + strlen(buf), win_size - strlen(buf),
165 cur_pos);
166 strlcat(buf, " ", win_size);
167
168 /* bandwidth usage */
169 format_rate(buf + strlen(buf), win_size - strlen(buf),
170 bytes_per_second);
170 (off_t)bytes_per_second);
171 strlcat(buf, "/s ", win_size);
172
173 /* ETA */
174 if (!transferred)
175 stalled += elapsed;
176 else
177 stalled = 0;
178

--- 40 unchanged lines hidden (view full) ---

219 refresh_progress_meter();
220
221 signal(SIGALRM, update_progress_meter);
222 alarm(UPDATE_INTERVAL);
223 errno = save_errno;
224}
225
226void
171 strlcat(buf, "/s ", win_size);
172
173 /* ETA */
174 if (!transferred)
175 stalled += elapsed;
176 else
177 stalled = 0;
178

--- 40 unchanged lines hidden (view full) ---

219 refresh_progress_meter();
220
221 signal(SIGALRM, update_progress_meter);
222 alarm(UPDATE_INTERVAL);
223 errno = save_errno;
224}
225
226void
227start_progress_meter(char *f, off_t filesize, off_t *stat)
227start_progress_meter(char *f, off_t filesize, off_t *ctr)
228{
229 struct winsize winsize;
230
231 start = last_update = time(NULL);
232 file = f;
233 end_pos = filesize;
234 cur_pos = 0;
228{
229 struct winsize winsize;
230
231 start = last_update = time(NULL);
232 file = f;
233 end_pos = filesize;
234 cur_pos = 0;
235 counter = stat;
235 counter = ctr;
236 stalled = 0;
237 bytes_per_second = 0;
238
239 if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize) != -1 &&
240 winsize.ws_col != 0) {
241 if (winsize.ws_col > MAX_WINSIZE)
242 win_size = MAX_WINSIZE;
243 else

--- 26 unchanged lines hidden ---
236 stalled = 0;
237 bytes_per_second = 0;
238
239 if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &winsize) != -1 &&
240 winsize.ws_col != 0) {
241 if (winsize.ws_col > MAX_WINSIZE)
242 win_size = MAX_WINSIZE;
243 else

--- 26 unchanged lines hidden ---