NetBSD/sbin/savecore/zopen.c

42 lines
849 B
C
Raw Normal View History

/* $NetBSD: zopen.c,v 1.2 2005/06/27 01:00:06 christos 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
__RCSID("$NetBSD: zopen.c,v 1.2 2005/06/27 01:00:06 christos 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)
{
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')
return (funopen(gz, xgzread, NULL, NULL, gzclose));
else
return (funopen(gz, NULL, xgzwrite, NULL, gzclose));
}