8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / boot / lib / libz / zopen.c
blobcde022dcf0e62e84c426fbbce650e04187bb6648
1 /*
2 * Public domain stdio wrapper for libz, written by Johan Danielsson.
3 */
5 #include <sys/cdefs.h>
6 __FBSDID("$FreeBSD$");
8 #include <stdio.h>
9 #include <zlib.h>
11 FILE *zopen(const char *fname, const char *mode);
13 /* convert arguments */
14 static int
15 xgzread(void *cookie, char *data, int size)
17 return gzread(cookie, data, size);
20 static int
21 xgzwrite(void *cookie, const char *data, int size)
23 return gzwrite(cookie, (void*)data, size);
26 static int
27 xgzclose(void *cookie)
29 return gzclose(cookie);
32 static fpos_t
33 xgzseek(void *cookie, fpos_t offset, int whence)
35 return gzseek(cookie, (z_off_t)offset, whence);
38 FILE *
39 zopen(const char *fname, const char *mode)
41 gzFile gz = gzopen(fname, mode);
42 if(gz == NULL)
43 return NULL;
45 if(*mode == 'r')
46 return (funopen(gz, xgzread, NULL, xgzseek, xgzclose));
47 else
48 return (funopen(gz, NULL, xgzwrite, xgzseek, xgzclose));