MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / gz_open

Function gz_open

zlib/gzio.c:98–208  ·  view source on GitHub ↗

=========================================================================== Opens a gzip (.gz) file for reading or writing. The mode parameter is as in fopen ("rb" or "wb"). The file is given either by file descriptor or path name (if fd == -1). gz_open returns NULL if the file could not be opened or if there was insufficient memory to allocate the (de)compression state; errno

(path, mode, fd)

Source from the content-addressed store, hash-verified

96 zlib error is Z_MEM_ERROR).
97*/
98local gzFile gz_open (path, mode, fd)
99 const char *path;
100 const char *mode;
101 int fd;
102{
103 int err;
104 int level = Z_DEFAULT_COMPRESSION; /* compression level */
105 int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
106 char *p = (char*)mode;
107 gz_stream *s;
108 char fmode[80]; /* copy of mode, without the compression level */
109 char *m = fmode;
110
111 if (!path || !mode) return Z_NULL;
112
113 s = (gz_stream *)ALLOC(sizeof(gz_stream));
114 if (!s) return Z_NULL;
115
116 s->stream.zalloc = (alloc_func)0;
117 s->stream.zfree = (free_func)0;
118 s->stream.opaque = (voidpf)0;
119 s->stream.next_in = s->inbuf = Z_NULL;
120 s->stream.next_out = s->outbuf = Z_NULL;
121 s->stream.avail_in = s->stream.avail_out = 0;
122 s->file = NULL;
123 s->z_err = Z_OK;
124 s->z_eof = 0;
125 s->in = 0;
126 s->out = 0;
127 s->back = EOF;
128 s->crc = crc32(0L, Z_NULL, 0);
129 s->msg = NULL;
130 s->transparent = 0;
131
132 s->path = (char*)ALLOC(strlen(path)+1);
133 if (s->path == NULL) {
134 return destroy(s), (gzFile)Z_NULL;
135 }
136 strcpy(s->path, path); /* do this early for debugging */
137
138 s->mode = '\0';
139 do {
140 if (*p == 'r') s->mode = 'r';
141 if (*p == 'w' || *p == 'a') s->mode = 'w';
142 if (*p >= '0' && *p <= '9') {
143 level = *p - '0';
144 } else if (*p == 'f') {
145 strategy = Z_FILTERED;
146 } else if (*p == 'h') {
147 strategy = Z_HUFFMAN_ONLY;
148 } else if (*p == 'R') {
149 strategy = Z_RLE;
150 } else {
151 *m++ = *p; /* copy the mode */
152 }
153 } while (*p++ && m != fmode + sizeof(fmode));
154 if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
155

Callers 2

ZEXPORTFunction · 0.85
gzdopenFunction · 0.85

Calls 3

crc32Function · 0.85
check_headerFunction · 0.85
destroyFunction · 0.70

Tested by

no test coverage detected