MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / gz_read

Function gz_read

extern/zlib/src/gzread.c:268–342  ·  view source on GitHub ↗

Read len bytes into buf from file, or less than len up to the end of the input. Return the number of bytes read. If zero is returned, either the end of file was reached, or there was an error. state->err must be consulted in that case to determine which. */

Source from the content-addressed store, hash-verified

266 end of file was reached, or there was an error. state->err must be
267 consulted in that case to determine which. */
268local z_size_t gz_read(gz_statep state, voidp buf, z_size_t len) {
269 z_size_t got;
270 unsigned n;
271
272 /* if len is zero, avoid unnecessary operations */
273 if (len == 0)
274 return 0;
275
276 /* process a skip request */
277 if (state->seek) {
278 state->seek = 0;
279 if (gz_skip(state, state->skip) == -1)
280 return 0;
281 }
282
283 /* get len bytes to buf, or less than len if at the end */
284 got = 0;
285 do {
286 /* set n to the maximum amount of len that fits in an unsigned int */
287 n = (unsigned)-1;
288 if (n > len)
289 n = (unsigned)len;
290
291 /* first just try copying data from the output buffer */
292 if (state->x.have) {
293 if (state->x.have < n)
294 n = state->x.have;
295 memcpy(buf, state->x.next, n);
296 state->x.next += n;
297 state->x.have -= n;
298 }
299
300 /* output buffer empty -- return if we're at the end of the input */
301 else if (state->eof && state->strm.avail_in == 0) {
302 state->past = 1; /* tried to read past end */
303 break;
304 }
305
306 /* need output data -- for small len or new stream load up our output
307 buffer */
308 else if (state->how == LOOK || n < (state->size << 1)) {
309 /* get more output, looking for header if required */
310 if (gz_fetch(state) == -1)
311 return 0;
312 continue; /* no progress yet -- go back to copy above */
313 /* the copy above assures that we will leave with space in the
314 output buffer, allowing at least one gzungetc() to succeed */
315 }
316
317 /* large len -- read directly into user buffer */
318 else if (state->how == COPY) { /* read directly */
319 if (gz_load(state, (unsigned char *)buf, n, &n) == -1)
320 return 0;
321 }
322
323 /* large len -- decompress directly into user buffer */
324 else { /* state->how == GZIP */
325 state->strm.avail_out = n;

Callers 3

gzreadFunction · 0.85
gzfreadFunction · 0.85
gzgetcFunction · 0.85

Calls 4

gz_skipFunction · 0.85
gz_fetchFunction · 0.85
gz_loadFunction · 0.85
gz_decompFunction · 0.85

Tested by

no test coverage detected