diff options
author | 2003-12-29 21:20:55 +0000 | |
---|---|---|
committer | 2003-12-29 21:20:55 +0000 | |
commit | 25ef24054180a7e7e53309ed00baed7a1f4516a5 (patch) | |
tree | a53ce3584d71e595914a5403760b10cfa20687d4 | |
parent | Add support for % and & units to indicate percent of total space and (diff) | |
download | wireguard-openbsd-25ef24054180a7e7e53309ed00baed7a1f4516a5.tar.xz wireguard-openbsd-25ef24054180a7e7e53309ed00baed7a1f4516a5.zip |
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@
-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; } |