zopen.c revision 256644
1/* 2 * Public domain stdio wrapper for libz, written by Johan Danielsson. 3 */ 4 5#include <sys/cdefs.h> 6__FBSDID("$FreeBSD: head/lib/libz/zopen.c 84228 2001-09-30 22:39:00Z dillon $"); 7 8#include <stdio.h> 9#include <zlib.h> 10 11FILE *zopen(const char *fname, const char *mode); 12 13/* convert arguments */ 14static int 15xgzread(void *cookie, char *data, int size) 16{ 17 return gzread(cookie, data, size); 18} 19 20static int 21xgzwrite(void *cookie, const char *data, int size) 22{ 23 return gzwrite(cookie, (void*)data, size); 24} 25 26static int 27xgzclose(void *cookie) 28{ 29 return gzclose(cookie); 30} 31 32static fpos_t 33xgzseek(void *cookie, fpos_t offset, int whence) 34{ 35 return gzseek(cookie, (z_off_t)offset, whence); 36} 37 38FILE * 39zopen(const char *fname, const char *mode) 40{ 41 gzFile gz = gzopen(fname, mode); 42 if(gz == NULL) 43 return NULL; 44 45 if(*mode == 'r') 46 return (funopen(gz, xgzread, NULL, xgzseek, xgzclose)); 47 else 48 return (funopen(gz, NULL, xgzwrite, xgzseek, xgzclose)); 49} 50