summaryrefslogtreecommitdiffstats
path: root/usr.bin/grep/binary.c
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2005-02-07 08:47:18 +0000
committerotto <otto@openbsd.org>2005-02-07 08:47:18 +0000
commit71d182b28ddc2e273c98f99720cb0f32f773122b (patch)
treefdf5ed2aa019d56dc1c7db59c385d5e6018a755b /usr.bin/grep/binary.c
parentIn list mode (which implies test mode), do not forget to initialize (diff)
downloadwireguard-openbsd-71d182b28ddc2e273c98f99720cb0f32f773122b.tar.xz
wireguard-openbsd-71d182b28ddc2e273c98f99720cb0f32f773122b.zip
Due to a braindead zlib, the test for seekability of a gzstream using
gzseek(f, 0L, SEEK_CUR) does not work as expected. Instead test the underlying stream and remember that. This repairs echo foo | gzip | zgrep foo. Problem spotted by Han Boetes in PR 4089; ok millert@
Diffstat (limited to 'usr.bin/grep/binary.c')
-rw-r--r--usr.bin/grep/binary.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/usr.bin/grep/binary.c b/usr.bin/grep/binary.c
index 1736a6bd1b8..fcc15419a02 100644
--- a/usr.bin/grep/binary.c
+++ b/usr.bin/grep/binary.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: binary.c,v 1.13 2004/09/15 22:35:36 deraadt Exp $ */
+/* $OpenBSD: binary.c,v 1.14 2005/02/07 08:47:18 otto Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@@ -27,6 +27,7 @@
*/
#include <ctype.h>
+#include <err.h>
#include <stdio.h>
#include <zlib.h>
@@ -41,7 +42,7 @@ bin_file(FILE *f)
int i, m;
int ret = 0;
- if (isatty(fileno(f)) || fseek(f, 0L, SEEK_SET) == -1)
+ if (fseek(f, 0L, SEEK_SET) == -1)
return 0;
if ((m = (int)fread(buf, 1, BUFSIZ, f)) == 0)
@@ -77,7 +78,8 @@ gzbin_file(gzFile *f)
break;
}
- gzrewind(f);
+ if (gzrewind(f) != 0)
+ err(1, "gzbin_file");
return ret;
}
#endif