svn commit: r283945 - in head: contrib/mdocml usr.bin/mandoc

Baptiste Daroussin bapt at FreeBSD.org
Wed Jun 3 13:32:30 UTC 2015


Author: bapt
Date: Wed Jun  3 13:32:28 2015
New Revision: 283945
URL: https://svnweb.freebsd.org/changeset/base/283945

Log:
  Replace the gunzip(1) system by a minimalistic zlib based implementation.
  
  This allows to not depend on gunzip(1) at bootstrap time, and is good enough to
  wait for upstream real implementation using zlib.

Modified:
  head/contrib/mdocml/read.c
  head/usr.bin/mandoc/Makefile

Modified: head/contrib/mdocml/read.c
==============================================================================
--- head/contrib/mdocml/read.c	Wed Jun  3 13:26:15 2015	(r283944)
+++ head/contrib/mdocml/read.c	Wed Jun  3 13:32:28 2015	(r283945)
@@ -28,6 +28,7 @@
 #include <assert.h>
 #include <ctype.h>
 #include <errno.h>
+#include <err.h>
 #include <fcntl.h>
 #include <stdarg.h>
 #include <stdint.h>
@@ -35,6 +36,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <zlib.h>
 
 #include "mandoc.h"
 #include "mandoc_aux.h"
@@ -792,6 +794,27 @@ mparse_readfd(struct mparse *curp, int f
 	return(curp->file_status);
 }
 
+/*
+ * hack to avoid depending on gnuzip(1) waiting for upstream proper
+ * support
+ */
+static int
+gunzip(const char *file)
+{
+	gzFile		  gz;
+	char		  buf[8192];
+	int		  r;
+
+	gz = gzopen(file, "r");
+	if (gz == NULL)
+		err(EXIT_FAILURE, "cannot open %s", file);
+
+	while ((r = gzread(gz, buf, sizeof(buf))) > 0)
+		fwrite(buf, 1, r, stdout);
+
+	gzclose(gz);
+	return (EXIT_SUCCESS);
+}
 enum mandoclevel
 mparse_open(struct mparse *curp, int *fd, const char *file)
 {
@@ -846,9 +869,7 @@ mparse_open(struct mparse *curp, int *fd
 			perror("dup");
 			exit((int)MANDOCLEVEL_SYSERR);
 		}
-		execlp("gunzip", "gunzip", "-c", file, NULL);
-		perror("exec");
-		exit((int)MANDOCLEVEL_SYSERR);
+		exit(gunzip(file));
 	default:
 		close(pfd[1]);
 		*fd = pfd[0];

Modified: head/usr.bin/mandoc/Makefile
==============================================================================
--- head/usr.bin/mandoc/Makefile	Wed Jun  3 13:26:15 2015	(r283944)
+++ head/usr.bin/mandoc/Makefile	Wed Jun  3 13:32:28 2015	(r283945)
@@ -84,6 +84,6 @@ WARNS?=	2
 CFLAGS+= -DHAVE_CONFIG_H \
 	 -I${.CURDIR}/../../lib/libohash/ \
 	 -I${.CURDIR}/../../contrib/sqlite3
-LIBADD=	ohash sqlite3
+LIBADD=	ohash sqlite3 z
 
 .include <bsd.prog.mk>


More information about the svn-src-head mailing list