1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-29 08:08:37 +00:00

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:
Baptiste Daroussin 2015-06-03 13:32:28 +00:00
parent 2ecf70de02
commit 09faefdd44
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=283945
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>