zlib: Upgrade from version 1.2.5 to version 1.2.7
[dragonfly.git] / lib / libz / zopen.c
CommitLineData
984263bc
MD
1/*
2 * Public domain stdio wrapper for libz, written by Johan Danielsson.
1de703da
MD
3 *
4 * $FreeBSD: src/lib/libz/zopen.c,v 1.2.2.2 2003/02/01 13:33:12 sobomax Exp $
984263bc
MD
5 */
6
984263bc
MD
7#include <stdio.h>
8#include <zlib.h>
9
10FILE *zopen(const char *fname, const char *mode);
11
12/* convert arguments */
13static int
14xgzread(void *cookie, char *data, int size)
15{
16 return gzread(cookie, data, size);
17}
18
19static int
20xgzwrite(void *cookie, const char *data, int size)
21{
22 return gzwrite(cookie, (void*)data, size);
23}
24
ab767382
JM
25static int
26xgzclose(void *cookie)
27{
28 return gzclose((gzFile) cookie);
29}
30
984263bc
MD
31FILE *
32zopen(const char *fname, const char *mode)
33{
34 gzFile gz = gzopen(fname, mode);
35 if(gz == NULL)
36 return NULL;
37
38 if(*mode == 'r')
ab767382 39 return (funopen(gz, xgzread, NULL, NULL, xgzclose));
984263bc 40 else
ab767382 41 return (funopen(gz, NULL, xgzwrite, NULL, xgzclose));
984263bc 42}