diff options
author | bapt <bapt@FreeBSD.org> | 2015-06-03 13:32:28 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2015-06-03 13:32:28 +0000 |
commit | 635343e5d69d48aae0be545de8a5145ec1404ecf (patch) | |
tree | e60b60e30c6c209b606bd1475fe9b858c1e214c6 /contrib/mdocml | |
parent | 0bbde920403a75d068e6edfd74cedfba8cb791a0 (diff) | |
download | FreeBSD-src-635343e5d69d48aae0be545de8a5145ec1404ecf.zip FreeBSD-src-635343e5d69d48aae0be545de8a5145ec1404ecf.tar.gz |
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.
Diffstat (limited to 'contrib/mdocml')
-rw-r--r-- | contrib/mdocml/read.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/contrib/mdocml/read.c b/contrib/mdocml/read.c index 471d415..a34c9ff 100644 --- a/contrib/mdocml/read.c +++ b/contrib/mdocml/read.c @@ -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 fd, const char *file) 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, const char *file) 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]; |