From cb3a3b2a12665839afe16fac481ebb264144e362 Mon Sep 17 00:00:00 2001 From: kris Date: Thu, 6 Sep 2001 09:14:49 +0000 Subject: Add zopen(), a stdio wrapper for gzipped data streams. Obtained from: NetBSD --- lib/libz/Makefile | 3 ++- lib/libz/zopen.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 lib/libz/zopen.c (limited to 'lib/libz') diff --git a/lib/libz/Makefile b/lib/libz/Makefile index c467e8b..34ac28f 100644 --- a/lib/libz/Makefile +++ b/lib/libz/Makefile @@ -17,7 +17,8 @@ CFLAGS+= -DHAS_snprintf -DHAS_vsnprintf CLEANFILES+= example.o example foo.gz minigzip.o minigzip SRCS = adler32.c compress.c crc32.c gzio.c uncompr.c deflate.c trees.c \ - zutil.c inflate.c infblock.c inftrees.c infcodes.c infutil.c inffast.c + zutil.c inflate.c infblock.c inftrees.c infcodes.c infutil.c \ + inffast.c zopen.c INCS= zconf.h zlib.h minigzip: all minigzip.o diff --git a/lib/libz/zopen.c b/lib/libz/zopen.c new file mode 100644 index 0000000..33e6c76 --- /dev/null +++ b/lib/libz/zopen.c @@ -0,0 +1,39 @@ +/* + * Public domain stdio wrapper for libz, written by Johan Danielsson. + */ + +#ifndef lint +static const char rcsid[] = + "$FreeBSD$"; +#endif /* not lint */ + +#include +#include + +FILE *zopen(const char *fname, const char *mode); + +/* convert arguments */ +static int +xgzread(void *cookie, char *data, int size) +{ + return gzread(cookie, data, size); +} + +static int +xgzwrite(void *cookie, const char *data, int size) +{ + return gzwrite(cookie, (void*)data, size); +} + +FILE * +zopen(const char *fname, const char *mode) +{ + gzFile gz = gzopen(fname, mode); + if(gz == NULL) + return NULL; + + if(*mode == 'r') + return (funopen(gz, xgzread, NULL, NULL, gzclose)); + else + return (funopen(gz, NULL, xgzwrite, NULL, gzclose)); +} -- cgit v1.1