X-Git-Url: https://git.cameronkatri.com/bsd-progress.git/blobdiff_plain/358c353b6dddd98a33c67d1e182f6810bdd45254..HEAD:/progress.c diff --git a/progress.c b/progress.c index 5e4f8ee..a921ac9 100644 --- a/progress.c +++ b/progress.c @@ -1,4 +1,4 @@ -/* $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. @@ -29,42 +29,41 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#define _GNU_SOURCE + #include #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 -#include -#include #include -#include +#include #include -#include -#include #include #include #include -#include -#include #include #include -#include +#include #include #include #include -#include -#include -#include #include + /* 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) @@ -84,7 +83,6 @@ usage(void) exit(EXIT_FAILURE); } - int main(int argc, char *argv[]) { @@ -97,7 +95,7 @@ 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]); @@ -209,10 +207,10 @@ main(int argc, char *argv[]) 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) @@ -237,14 +235,24 @@ main(int argc, char *argv[]) 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;