MCPcopy Create free account
hub / github.com/F-Stack/f-stack / gz_open

Function gz_open

freebsd/contrib/zlib/test/minigzip.c:196–232  ·  view source on GitHub ↗
(path, fd, mode)

Source from the content-addressed store, hash-verified

194}
195
196gzFile gz_open(path, fd, mode)
197 const char *path;
198 int fd;
199 const char *mode;
200{
201 gzFile gz;
202 int ret;
203
204 gz = malloc(sizeof(struct gzFile_s));
205 if (gz == NULL)
206 return NULL;
207 gz->write = strchr(mode, 'w') != NULL;
208 gz->strm.zalloc = myalloc;
209 gz->strm.zfree = myfree;
210 gz->strm.opaque = Z_NULL;
211 if (gz->write)
212 ret = deflateInit2(&(gz->strm), -1, 8, 15 + 16, 8, 0);
213 else {
214 gz->strm.next_in = 0;
215 gz->strm.avail_in = Z_NULL;
216 ret = inflateInit2(&(gz->strm), 15 + 16);
217 }
218 if (ret != Z_OK) {
219 free(gz);
220 return NULL;
221 }
222 gz->file = path == NULL ? fdopen(fd, gz->write ? "wb" : "rb") :
223 fopen(path, gz->write ? "wb" : "rb");
224 if (gz->file == NULL) {
225 gz->write ? deflateEnd(&(gz->strm)) : inflateEnd(&(gz->strm));
226 free(gz);
227 return NULL;
228 }
229 gz->err = 0;
230 gz->msg = "";
231 return gz;
232}
233
234int gzwrite OF((gzFile, const void *, unsigned));
235

Callers 2

gzopenFunction · 0.70
gzdopenFunction · 0.70

Calls 5

mallocFunction · 0.85
strchrFunction · 0.85
fdopenFunction · 0.85
deflateEndFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected