diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2011-10-12 23:24:31 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2011-12-11 18:22:04 -0800 |
commit | 98f5779f4257682ba9b5fc490557618e3f15f84b (patch) | |
tree | 09082da8f556b04ba8aa299cf55eb979a3dfa063 /gzlib.c | |
parent | 70e3b1ca56f2ffe8944d3ac0d59b8781127bf94f (diff) | |
download | zlib-98f5779f4257682ba9b5fc490557618e3f15f84b.tar.gz zlib-98f5779f4257682ba9b5fc490557618e3f15f84b.tar.bz2 zlib-98f5779f4257682ba9b5fc490557618e3f15f84b.zip |
Fix gzeof() to behave just like feof() when read is not past end of file.
Before, gzeof() would return true (accurately) when the last read request
went just up to the end of the uncompressed data. In the analogous case,
feof() would return false, only returning true when a read request goes
past the end of the file. This patch corrects gzeof() to behave in the
same way as feof(), as noted in the zlib.h documentation.
Diffstat (limited to 'gzlib.c')
-rw-r--r-- | gzlib.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -78,6 +78,7 @@ local void gz_reset(state) | |||
78 | state->x.have = 0; /* no output data available */ | 78 | state->x.have = 0; /* no output data available */ |
79 | if (state->mode == GZ_READ) { /* for reading ... */ | 79 | if (state->mode == GZ_READ) { /* for reading ... */ |
80 | state->eof = 0; /* not at end of file */ | 80 | state->eof = 0; /* not at end of file */ |
81 | state->past = 0; /* have not read past end yet */ | ||
81 | state->how = LOOK; /* look for gzip header */ | 82 | state->how = LOOK; /* look for gzip header */ |
82 | } | 83 | } |
83 | state->seek = 0; /* no seek request pending */ | 84 | state->seek = 0; /* no seek request pending */ |
@@ -331,6 +332,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence) | |||
331 | return -1; | 332 | return -1; |
332 | state->x.have = 0; | 333 | state->x.have = 0; |
333 | state->eof = 0; | 334 | state->eof = 0; |
335 | state->past = 0; | ||
334 | state->seek = 0; | 336 | state->seek = 0; |
335 | gz_error(state, Z_OK, NULL); | 337 | gz_error(state, Z_OK, NULL); |
336 | state->strm.avail_in = 0; | 338 | state->strm.avail_in = 0; |
@@ -453,8 +455,7 @@ int ZEXPORT gzeof(file) | |||
453 | return 0; | 455 | return 0; |
454 | 456 | ||
455 | /* return end-of-file state */ | 457 | /* return end-of-file state */ |
456 | return state->mode == GZ_READ ? | 458 | return state->mode == GZ_READ ? state->past : 0; |
457 | (state->eof && state->strm.avail_in == 0 && state->x.have == 0) : 0; | ||
458 | } | 459 | } |
459 | 460 | ||
460 | /* -- see zlib.h -- */ | 461 | /* -- see zlib.h -- */ |
@@ -491,8 +492,10 @@ void ZEXPORT gzclearerr(file) | |||
491 | return; | 492 | return; |
492 | 493 | ||
493 | /* clear error and end-of-file */ | 494 | /* clear error and end-of-file */ |
494 | if (state->mode == GZ_READ) | 495 | if (state->mode == GZ_READ) { |
495 | state->eof = 0; | 496 | state->eof = 0; |
497 | state->past = 0; | ||
498 | } | ||
496 | gz_error(state, Z_OK, NULL); | 499 | gz_error(state, Z_OK, NULL); |
497 | } | 500 | } |
498 | 501 | ||