Module Name:    src
Committed By:   christos
Date:           Sun Aug 12 09:03:21 UTC 2018

Modified Files:
        src/usr.bin/grep: Makefile file.c grep.c grep.h

Log Message:
add WITHOUT_GZIP for the tools build.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/grep/Makefile src/usr.bin/grep/file.c \
    src/usr.bin/grep/grep.h
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/grep/grep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/grep/Makefile
diff -u src/usr.bin/grep/Makefile:1.9 src/usr.bin/grep/Makefile:1.10
--- src/usr.bin/grep/Makefile:1.9	Sun Aug 12 04:00:32 2018
+++ src/usr.bin/grep/Makefile	Sun Aug 12 05:03:21 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.9 2018/08/12 08:00:32 christos Exp $
+#	$NetBSD: Makefile,v 1.10 2018/08/12 09:03:21 christos Exp $
 #	$FreeBSD: head/usr.bin/grep/Makefile 210389 2010-07-22 19:11:57Z gabor $
 #	$OpenBSD: Makefile,v 1.6 2003/06/25 15:00:04 millert Exp $
 
@@ -17,8 +17,10 @@ MLINKS=	grep.1 egrep.1	\
 	grep.1 zegrep.1	\
 	grep.1 zfgrep.1
 
+.if empty(HOST_CPPFLAGS:M*-DWITHOUT_GZIP*)
 LDADD+=	-lz
 DPADD+=	${LIBZ}
+.endif
 
 .if empty(HOST_CPPFLAGS:M*-DWITHOUT_BZ2*)
 LDADD+=	-lbz2
Index: src/usr.bin/grep/file.c
diff -u src/usr.bin/grep/file.c:1.9 src/usr.bin/grep/file.c:1.10
--- src/usr.bin/grep/file.c:1.9	Sun Aug 12 03:53:19 2018
+++ src/usr.bin/grep/file.c	Sun Aug 12 05:03:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: file.c,v 1.9 2018/08/12 07:53:19 christos Exp $	*/
+/*	$NetBSD: file.c,v 1.10 2018/08/12 09:03:21 christos Exp $	*/
 /*	$FreeBSD: head/usr.bin/grep/file.c 211496 2010-08-19 09:28:59Z des $	*/
 /*	$OpenBSD: file.c,v 1.11 2010/07/02 20:48:48 nicm Exp $	*/
 
@@ -35,7 +35,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: file.c,v 1.9 2018/08/12 07:53:19 christos Exp $");
+__RCSID("$NetBSD: file.c,v 1.10 2018/08/12 09:03:21 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -56,7 +56,9 @@ __RCSID("$NetBSD: file.c,v 1.9 2018/08/1
 #define	MAXBUFSIZ	(32 * 1024)
 #define	LNBUFBUMP	80
 
+#ifndef WITHOUT_GZIP
 static gzFile gzbufdesc;
+#endif
 #ifndef WITHOUT_BZ2
 static BZFILE* bzbufdesc;
 #endif
@@ -71,16 +73,21 @@ static size_t lnbuflen;
 static inline int
 grep_refill(struct file *f)
 {
-	ssize_t nr;
+	ssize_t nr = -1;
 	int bzerr;
 
 	bufpos = buffer;
 	bufrem = 0;
 
+#ifndef WITHOUT_GZIP
 	if (filebehave == FILE_GZIP) {
 		nr = gzread(gzbufdesc, buffer, MAXBUFSIZ);
+		if (nr == -1)
+			return -1;
+	}
+#endif
 #ifndef WITHOUT_BZ2
-	} else if (filebehave == FILE_BZIP && bzbufdesc != NULL) {
+	if (filebehave == FILE_BZIP && bzbufdesc != NULL) {
 		nr = BZ2_bzRead(&bzerr, bzbufdesc, buffer, MAXBUFSIZ);
 		switch (bzerr) {
 		case BZ_OK:
@@ -106,9 +113,13 @@ grep_refill(struct file *f)
 			/* Make sure we exit with an error */
 			nr = -1;
 		}
+		if (nr == -1)
+			return -1;
+	}
 #endif
-	} else
+	if (nr == -1) {
 		nr = read(f->fd, buffer, MAXBUFSIZ);
+	}
 
 	if (nr < 0)
 		return (-1);
@@ -196,9 +207,11 @@ static inline struct file *
 grep_file_init(struct file *f)
 {
 
+#ifndef WITHOUT_GZIP
 	if (filebehave == FILE_GZIP &&
 	    (gzbufdesc = gzdopen(f->fd, "r")) == NULL)
 		goto error;
+#endif
 
 #ifndef WITHOUT_BZ2
 	if (filebehave == FILE_BZIP &&
Index: src/usr.bin/grep/grep.h
diff -u src/usr.bin/grep/grep.h:1.9 src/usr.bin/grep/grep.h:1.10
--- src/usr.bin/grep/grep.h:1.9	Sun Aug 12 03:53:19 2018
+++ src/usr.bin/grep/grep.h	Sun Aug 12 05:03:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: grep.h,v 1.9 2018/08/12 07:53:19 christos Exp $	*/
+/*	$NetBSD: grep.h,v 1.10 2018/08/12 09:03:21 christos Exp $	*/
 /*	$OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $	*/
 /*	$FreeBSD: head/usr.bin/grep/grep.h 211496 2010-08-19 09:28:59Z des $	*/
 
@@ -36,7 +36,9 @@
 #include <regex.h>
 #include <stdbool.h>
 #include <stdio.h>
+#ifndef WITHOUT_GZIP
 #include <zlib.h>
+#endif
 
 #ifdef WITHOUT_NLS
 #define getstr(n)	 errstr[n]

Index: src/usr.bin/grep/grep.c
diff -u src/usr.bin/grep/grep.c:1.14 src/usr.bin/grep/grep.c:1.15
--- src/usr.bin/grep/grep.c:1.14	Sun Aug 12 03:53:19 2018
+++ src/usr.bin/grep/grep.c	Sun Aug 12 05:03:21 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: grep.c,v 1.14 2018/08/12 07:53:19 christos Exp $	*/
+/*	$NetBSD: grep.c,v 1.15 2018/08/12 09:03:21 christos Exp $	*/
 /* 	$FreeBSD: head/usr.bin/grep/grep.c 211519 2010-08-19 22:55:17Z delphij $	*/
 /*	$OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $	*/
 
@@ -34,7 +34,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: grep.c,v 1.14 2018/08/12 07:53:19 christos Exp $");
+__RCSID("$NetBSD: grep.c,v 1.15 2018/08/12 09:03:21 christos Exp $");
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -170,7 +170,9 @@ static const char optstr[] =
 struct option long_options[] =
 {
 	{"binary-files",	required_argument,	NULL, BIN_OPT},
+#ifndef WITHOUT_GZIP
 	{"decompress",          no_argument,            NULL, DECOMPRESS_OPT},
+#endif
 	{"help",		no_argument,		NULL, HELP_OPT},
 	{"mmap",		no_argument,		NULL, MMAP_OPT},
 	{"line-buffered",	no_argument,		NULL, LINEBUF_OPT},
@@ -340,6 +342,7 @@ main(int argc, char *argv[])
 	case 'g':
 		grepbehave = GREP_BASIC;
 		break;
+#ifndef WITHOUT_GZIP
 	case 'z':
 		filebehave = FILE_GZIP;
 		switch(__progname[1]) {
@@ -354,6 +357,7 @@ main(int argc, char *argv[])
 			break;
 		}
 		break;
+#endif
 	}
 
 	lastc = '\0';
@@ -600,9 +604,11 @@ main(int argc, char *argv[])
 			    strcasecmp("no", optarg) != 0)
 				errx(2, getstr(3), "--color");
 			break;
+#ifndef WITHOUT_GZIP
 		case DECOMPRESS_OPT:
 			filebehave = FILE_GZIP;
 			break;
+#endif
 		case LABEL_OPT:
 			label = optarg;
 			break;

Reply via email to