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

Function gz_open

freebsd/contrib/zstd/zlibWrapper/examples/minigzip.c:201–237  ·  view source on GitHub ↗
(path, fd, mode)

Source from the content-addressed store, hash-verified

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

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