summaryrefslogtreecommitdiff
path: root/gzread.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-10-12 23:24:31 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-12-11 18:22:04 -0800
commit98f5779f4257682ba9b5fc490557618e3f15f84b (patch)
tree09082da8f556b04ba8aa299cf55eb979a3dfa063 /gzread.c
parent70e3b1ca56f2ffe8944d3ac0d59b8781127bf94f (diff)
downloadzlib-98f5779f4257682ba9b5fc490557618e3f15f84b.tar.gz
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 'gzread.c')
-rw-r--r--gzread.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/gzread.c b/gzread.c
index 521e26f..cda7935 100644
--- a/gzread.c
+++ b/gzread.c
@@ -329,8 +329,10 @@ int ZEXPORT gzread(file, buf, len)
}
/* output buffer empty -- return if we're at the end of the input */
- else if (state->eof && strm->avail_in == 0)
+ else if (state->eof && strm->avail_in == 0) {
+ state->past = 1; /* tried to read past end */
break;
+ }
/* need output data -- for small len or new stream load up our output
buffer */
@@ -437,6 +439,7 @@ int ZEXPORT gzungetc(c, file)
state->x.next = state->out + (state->size << 1) - 1;
state->x.next[0] = c;
state->x.pos--;
+ state->past = 0;
return c;
}
@@ -458,6 +461,7 @@ int ZEXPORT gzungetc(c, file)
state->x.next--;
state->x.next[0] = c;
state->x.pos--;
+ state->past = 0;
return c;
}
@@ -499,9 +503,8 @@ char * ZEXPORT gzgets(file, buf, len)
if (state->x.have == 0 && gz_fetch(state) == -1)
return NULL; /* error */
if (state->x.have == 0) { /* end of file */
- if (buf == str) /* got bupkus */
- return NULL;
- break; /* got something -- return it */
+ state->past = 1; /* read past end */
+ break; /* return what we have */
}
/* look for end-of-line in current output buffer */
@@ -519,7 +522,9 @@ char * ZEXPORT gzgets(file, buf, len)
buf += n;
} while (left && eol == NULL);
- /* found end-of-line or out of space -- terminate string and return it */
+ /* return terminated string, or if nothing, end of file */
+ if (buf == str)
+ return NULL;
buf[0] = 0;
return str;
}