aboutsummaryrefslogtreecommitdiff
path: root/gzlib.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2025-02-21 14:22:16 -0800
committerMark Adler <madler@alumni.caltech.edu>2025-02-25 00:31:37 -0800
commita4e4521ee1303b756a8f96c18cdf4729327b687d (patch)
tree6f2e178d078a420fe9731976944874cbaf10f438 /gzlib.c
parentaa27ba467717707881e4ae925849e6229ceabf38 (diff)
downloadzlib-a4e4521ee1303b756a8f96c18cdf4729327b687d.tar.gz
zlib-a4e4521ee1303b756a8f96c18cdf4729327b687d.tar.bz2
zlib-a4e4521ee1303b756a8f96c18cdf4729327b687d.zip
Have gz_skip() update how far it got for later continuation.
This also simplifies seek processing in general.
Diffstat (limited to 'gzlib.c')
-rw-r--r--gzlib.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/gzlib.c b/gzlib.c
index baa3e79d..2f9cdd4e 100644
--- a/gzlib.c
+++ b/gzlib.c
@@ -75,7 +75,7 @@ local void gz_reset(gz_statep state) {
75 } 75 }
76 else /* for writing ... */ 76 else /* for writing ... */
77 state->reset = 0; /* no deflateReset pending */ 77 state->reset = 0; /* no deflateReset pending */
78 state->seek = 0; /* no seek request pending */ 78 state->skip = 0; /* no seek request pending */
79 gz_error(state, Z_OK, NULL); /* clear error */ 79 gz_error(state, Z_OK, NULL); /* clear error */
80 state->x.pos = 0; /* no uncompressed data yet */ 80 state->x.pos = 0; /* no uncompressed data yet */
81 state->strm.avail_in = 0; /* no input data yet */ 81 state->strm.avail_in = 0; /* no input data yet */
@@ -362,9 +362,10 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
362 /* normalize offset to a SEEK_CUR specification */ 362 /* normalize offset to a SEEK_CUR specification */
363 if (whence == SEEK_SET) 363 if (whence == SEEK_SET)
364 offset -= state->x.pos; 364 offset -= state->x.pos;
365 else if (state->seek) 365 else {
366 offset += state->skip; 366 offset += state->past ? 0 : state->skip;
367 state->seek = 0; 367 state->skip = 0;
368 }
368 369
369 /* if within raw area while reading, just go there */ 370 /* if within raw area while reading, just go there */
370 if (state->mode == GZ_READ && state->how == COPY && 371 if (state->mode == GZ_READ && state->how == COPY &&
@@ -375,7 +376,7 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
375 state->x.have = 0; 376 state->x.have = 0;
376 state->eof = 0; 377 state->eof = 0;
377 state->past = 0; 378 state->past = 0;
378 state->seek = 0; 379 state->skip = 0;
379 gz_error(state, Z_OK, NULL); 380 gz_error(state, Z_OK, NULL);
380 state->strm.avail_in = 0; 381 state->strm.avail_in = 0;
381 state->x.pos += offset; 382 state->x.pos += offset;
@@ -404,10 +405,7 @@ z_off64_t ZEXPORT gzseek64(gzFile file, z_off64_t offset, int whence) {
404 } 405 }
405 406
406 /* request skip (if not zero) */ 407 /* request skip (if not zero) */
407 if (offset) { 408 state->skip = offset;
408 state->seek = 1;
409 state->skip = offset;
410 }
411 return state->x.pos + offset; 409 return state->x.pos + offset;
412} 410}
413 411
@@ -431,7 +429,7 @@ z_off64_t ZEXPORT gztell64(gzFile file) {
431 return -1; 429 return -1;
432 430
433 /* return position */ 431 /* return position */
434 return state->x.pos + (state->seek ? state->skip : 0); 432 return state->x.pos + (state->past ? 0 : state->skip);
435} 433}
436 434
437/* -- see zlib.h -- */ 435/* -- see zlib.h -- */