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.
This commit is contained in:
bapt 2015-06-03 13:32:28 +00:00
parent 0bbde92040
commit 635343e5d6
2 changed files with 25 additions and 4 deletions

View File

@ -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];

View File

@ -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>