Add zopen(), a stdio wrapper for gzipped data streams.

Obtained from:	NetBSD
This commit is contained in:
Kris Kennaway 2001-09-06 09:14:49 +00:00
parent 19372e6db7
commit 131ee164c7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=83138
2 changed files with 41 additions and 1 deletions

View File

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

39
lib/libz/zopen.c Normal file
View File

@ -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 <stdio.h>
#include <zlib.h>
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));
}