diff options
author | Can Erkin Acar <canacar@cvs.openbsd.org> | 2003-12-29 21:20:56 +0000 |
---|---|---|
committer | Can Erkin Acar <canacar@cvs.openbsd.org> | 2003-12-29 21:20:56 +0000 |
commit | 15def480445c3ce97a8bc64d0cc13b6aebba6b93 (patch) | |
tree | 4f9c3fe40df43f63aa986b8f6ce52a2ee8bdb643 /usr.bin | |
parent | 967a2a387aa0f52c9ef919f1f3dc3bb867b112b2 (diff) |
fix zgrep failure when the uncompressed file begins with a newline
also, search from the beginning if a stream or compressed file is
identified as 'binary'.
ok millert@, reported by tedu@, tested by jose@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/grep/binary.c | 21 | ||||
-rw-r--r-- | usr.bin/grep/file.c | 6 |
2 files changed, 16 insertions, 11 deletions
diff --git a/usr.bin/grep/binary.c b/usr.bin/grep/binary.c index 84805714355..7c27efab486 100644 --- a/usr.bin/grep/binary.c +++ b/usr.bin/grep/binary.c @@ -1,4 +1,4 @@ -/* $OpenBSD: binary.c,v 1.9 2003/09/18 22:29:30 beck Exp $ */ +/* $OpenBSD: binary.c,v 1.10 2003/12/29 21:20:55 canacar Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -37,6 +37,7 @@ bin_file(FILE *f) { char buf[BUFSIZ]; int i, m; + int ret = 0; if (fseek(f, 0L, SEEK_SET) == -1) return 0; @@ -45,11 +46,13 @@ bin_file(FILE *f) return 0; for (i = 0; i < m; i++) - if (!isprint(buf[i]) && !isspace(buf[i])) - return 1; + if (!isprint(buf[i]) && !isspace(buf[i])) { + ret = 1; + break; + } rewind(f); - return 0; + return ret; } #ifndef NOZ @@ -58,6 +61,7 @@ gzbin_file(gzFile *f) { char buf[BUFSIZ]; int i, m; + int ret = 0; if (gzseek(f, 0L, SEEK_SET) == -1) return 0; @@ -66,11 +70,13 @@ gzbin_file(gzFile *f) return 0; for (i = 0; i < m; i++) - if (!isprint(buf[i]) && !isspace(buf[i])) - return 1; + if (!isprint(buf[i]) && !isspace(buf[i])) { + ret = 1; + break; + } gzrewind(f); - return 0; + return ret; } #endif @@ -83,6 +89,5 @@ mmbin_file(mmf_t *f) for (i = 0; i < BUFSIZ && i < f->len; i++) if (!isprint(f->base[i]) && !isspace(f->base[i])) return 1; - mmrewind(f); return 0; } diff --git a/usr.bin/grep/file.c b/usr.bin/grep/file.c index eb6ff672976..aa9f5066e6a 100644 --- a/usr.bin/grep/file.c +++ b/usr.bin/grep/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.4 2003/07/10 17:02:48 millert Exp $ */ +/* $OpenBSD: file.c,v 1.5 2003/12/29 21:20:55 canacar Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -72,12 +72,12 @@ gzfgetln(gzFile *f, size_t *len) else errx(2, "%s: %s", fname, gzerrstr); } - if (c == '\n') - break; if (n >= lnbuflen) { lnbuflen *= 2; lnbuf = grep_realloc(lnbuf, ++lnbuflen); } + if (c == '\n') + break; lnbuf[n] = c; } |