1 /* 2 * Public domain stdio wrapper for libz, written by Johan Danielsson. 3 */ 4 5 #include <sys/cdefs.h> 6 __FBSDID("$FreeBSD$"); 7 8 #include <stdio.h> 9 #include <zlib.h> 10 11 FILE *zopen(const char *fname, const char *mode); 12 13 /* convert arguments */ 14 static int 15 xgzread(void *cookie, char *data, int size) 16 { 17 return gzread(cookie, data, size); 18 } 19 20 static int 21 xgzwrite(void *cookie, const char *data, int size) 22 { 23 return gzwrite(cookie, (void*)data, size); 24 } 25 26 FILE * 27 zopen(const char *fname, const char *mode) 28 { 29 gzFile gz = gzopen(fname, mode); 30 if(gz == NULL) 31 return NULL; 32 33 if(*mode == 'r') 34 return (funopen(gz, xgzread, NULL, NULL, gzclose)); 35 else 36 return (funopen(gz, NULL, xgzwrite, NULL, gzclose)); 37 } 38