2012-12-25 13:24:45 +04:00
|
|
|
/* $NetBSD: zopen.c,v 1.3 2012/12/25 09:24:45 mbalmer Exp $ */
|
2001-01-03 00:39:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Public domain stdio wrapper for libz, written by Johan Danielsson.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
2012-12-25 13:24:45 +04:00
|
|
|
__RCSID("$NetBSD: zopen.c,v 1.3 2012/12/25 09:24:45 mbalmer Exp $");
|
2001-01-03 00:39:37 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
2005-06-27 05:00:04 +04:00
|
|
|
return gzwrite(cookie, __UNCONST(data), size);
|
2001-01-03 00:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FILE *
|
|
|
|
zopen(const char *fname, const char *mode)
|
|
|
|
{
|
|
|
|
gzFile gz = gzopen(fname, mode);
|
|
|
|
if(gz == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(*mode == 'r')
|
2012-12-25 13:24:45 +04:00
|
|
|
return funopen(gz, xgzread, NULL, NULL, gzclose);
|
2001-01-03 00:39:37 +03:00
|
|
|
else
|
2012-12-25 13:24:45 +04:00
|
|
|
return funopen(gz, NULL, xgzwrite, NULL, gzclose);
|
2001-01-03 00:39:37 +03:00
|
|
|
}
|