2001-09-06 09:14:49 +00:00
|
|
|
/*
|
|
|
|
* Public domain stdio wrapper for libz, written by Johan Danielsson.
|
|
|
|
*/
|
|
|
|
|
2001-09-30 22:39:00 +00:00
|
|
|
#include <sys/cdefs.h>
|
2013-10-31 18:44:40 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
2001-09-06 09:14:49 +00:00
|
|
|
|
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2012-06-21 21:47:08 +00:00
|
|
|
static int
|
|
|
|
xgzclose(void *cookie)
|
|
|
|
{
|
|
|
|
return gzclose(cookie);
|
|
|
|
}
|
|
|
|
|
2013-10-16 17:16:40 +00:00
|
|
|
static fpos_t
|
|
|
|
xgzseek(void *cookie, fpos_t offset, int whence)
|
|
|
|
{
|
|
|
|
return gzseek(cookie, (z_off_t)offset, whence);
|
|
|
|
}
|
|
|
|
|
2001-09-06 09:14:49 +00:00
|
|
|
FILE *
|
|
|
|
zopen(const char *fname, const char *mode)
|
|
|
|
{
|
|
|
|
gzFile gz = gzopen(fname, mode);
|
|
|
|
if(gz == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(*mode == 'r')
|
2013-10-16 17:16:40 +00:00
|
|
|
return (funopen(gz, xgzread, NULL, xgzseek, xgzclose));
|
2001-09-06 09:14:49 +00:00
|
|
|
else
|
2013-10-16 17:16:40 +00:00
|
|
|
return (funopen(gz, NULL, xgzwrite, xgzseek, xgzclose));
|
2001-09-06 09:14:49 +00:00
|
|
|
}
|