aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhubertf <hubertf@NetBSD.org>2006-04-20 23:20:55 +0000
committerhubertf <hubertf@NetBSD.org>2006-04-20 23:20:55 +0000
commit16e2f809d038fe54555b3c59f36d98ef2906a0c9 (patch)
treecac46eaf372a6e5f80a166cebfb165306d0154e6
parent284ff9e24243e397e1710bcc7e3ae439474725fa (diff)
downloadbsd-progress-16e2f809d038fe54555b3c59f36d98ef2906a0c9.tar.gz
bsd-progress-16e2f809d038fe54555b3c59f36d98ef2906a0c9.tar.zst
bsd-progress-16e2f809d038fe54555b3c59f36d98ef2906a0c9.zip
Don't try to determining the size of what's coming when reading from a pipe.
Instead of reporting some bogus values, print no progress at all. (It's beyond me why stat(2) on a pipe returns funny values... see the PR below for some examples!) Fixes PR bin/33207 by myself. OK'd by mrg@
-rw-r--r--progress.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/progress.c b/progress.c
index 3272ba2..a598ec3 100644
--- a/progress.c
+++ b/progress.c
@@ -1,4 +1,4 @@
-/* $NetBSD: progress.c,v 1.11 2006/01/12 20:33:20 garbled Exp $ */
+/* $NetBSD: progress.c,v 1.12 2006/04/20 23:20:55 hubertf Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: progress.c,v 1.11 2006/01/12 20:33:20 garbled Exp $");
+__RCSID("$NetBSD: progress.c,v 1.12 2006/04/20 23:20:55 hubertf Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -132,8 +132,16 @@ main(int argc, char *argv[])
err(1, "%s", infile);
/* stat() to get the filesize unless overridden, or -z */
- if (!zflag && !lflag && (fstat(fd, &statb) == 0))
- filesize = statb.st_size;
+ if (!zflag && !lflag && (fstat(fd, &statb) == 0)) {
+ if (S_ISFIFO(statb.st_mode)) {
+ /* stat(2) on pipe may return only the
+ * first few bytes with more coming.
+ * Don't trust!
+ */
+ } else {
+ filesize = statb.st_size;
+ }
+ }
/* gzip -l the file if we have the name and -z is given */
if (zflag && !lflag && infile != NULL) {