-/* $NetBSD: progress.c,v 1.19 2011/09/16 15:39:28 joerg Exp $ */
+/* $NetBSD: progress.c,v 1.23 2021/01/07 12:02:52 lukem Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
* POSSIBILITY OF SUCH DAMAGE.
*/
+#define _GNU_SOURCE
+
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: progress.c,v 1.19 2011/09/16 15:39:28 joerg Exp $");
+__RCSID("$NetBSD: progress.c,v 1.23 2021/01/07 12:02:52 lukem Exp $");
#endif /* not lint */
#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/socket.h>
#include <sys/ioctl.h>
-#include <sys/time.h>
+#include <sys/stat.h>
#include <sys/wait.h>
-#include <netinet/in.h>
-#include <arpa/ftp.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
-#include <glob.h>
-#include <signal.h>
#include <inttypes.h>
#include <limits.h>
-#include <netdb.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <termios.h>
-#include <time.h>
-#include <tzfile.h>
#include <unistd.h>
+ /* LONGLONG */
+long long strsuftoll(const char *, const char *, long long, long long);
+ /* LONGLONG */
+long long strsuftollx(const char *, const char *, long long, long long,
+ char *, size_t);
+
#define GLOBAL /* force GLOBAL decls in progressbar.h to be
* declared */
#include "progressbar.h"
static void broken_pipe(int unused);
-__dead static void usage(void);
+static void usage(void);
static void
broken_pipe(int unused)
exit(EXIT_FAILURE);
}
-
int
main(int argc, char *argv[])
{
ssize_t nr, nw, off;
size_t buffersize;
struct stat statb;
- struct ttysize ts;
+ struct winsize wins;
setprogname(argv[0]);
progress = 1;
ttyout = eflag ? stderr : stdout;
- if (ioctl(fileno(ttyout), TIOCGSIZE, &ts) == -1)
+ if (ioctl(fileno(ttyout), TIOCGWINSZ, &wins) == -1)
ttywidth = 80;
else
- ttywidth = ts.ts_cols;
+ ttywidth = wins.ws_col;
fb_buf = malloc(buffersize);
if (fb_buf == NULL)
signal(SIGPIPE, broken_pipe);
progressmeter(-1);
- while ((nr = read(fd, fb_buf, buffersize)) > 0)
+ while (1) {
+ do {
+ nr = read(fd, fb_buf, buffersize);
+ } while (nr < 0 && errno == EINTR);
+ if (nr <= 0)
+ break;
for (off = 0; nr; nr -= nw, off += nw, bytes += nw)
if ((nw = write(outpipe[1], fb_buf + off,
(size_t) nr)) < 0) {
+ if (errno == EINTR) {
+ nw = 0;
+ continue;
+ }
progressmeter(1);
err(1, "writing %u bytes to output pipe",
(unsigned) nr);
}
+ }
close(outpipe[1]);
gzipstat = 0;