From 98f5779f4257682ba9b5fc490557618e3f15f84b Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Wed, 12 Oct 2011 23:24:31 -0700 Subject: 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. --- gzlib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'gzlib.c') diff --git a/gzlib.c b/gzlib.c index e53b6ab..d998d07 100644 --- a/gzlib.c +++ b/gzlib.c @@ -78,6 +78,7 @@ local void gz_reset(state) state->x.have = 0; /* no output data available */ if (state->mode == GZ_READ) { /* for reading ... */ state->eof = 0; /* not at end of file */ + state->past = 0; /* have not read past end yet */ state->how = LOOK; /* look for gzip header */ } state->seek = 0; /* no seek request pending */ @@ -331,6 +332,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence) return -1; state->x.have = 0; state->eof = 0; + state->past = 0; state->seek = 0; gz_error(state, Z_OK, NULL); state->strm.avail_in = 0; @@ -453,8 +455,7 @@ int ZEXPORT gzeof(file) return 0; /* return end-of-file state */ - return state->mode == GZ_READ ? - (state->eof && state->strm.avail_in == 0 && state->x.have == 0) : 0; + return state->mode == GZ_READ ? state->past : 0; } /* -- see zlib.h -- */ @@ -491,8 +492,10 @@ void ZEXPORT gzclearerr(file) return; /* clear error and end-of-file */ - if (state->mode == GZ_READ) + if (state->mode == GZ_READ) { state->eof = 0; + state->past = 0; + } gz_error(state, Z_OK, NULL); } -- cgit v1.2.1