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 /gzread.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 'gzread.c')
-rw-r--r-- | gzread.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -329,8 +329,10 @@ int ZEXPORT gzread(file, buf, len) | |||
329 | } | 329 | } |
330 | 330 | ||
331 | /* output buffer empty -- return if we're at the end of the input */ | 331 | /* output buffer empty -- return if we're at the end of the input */ |
332 | else if (state->eof && strm->avail_in == 0) | 332 | else if (state->eof && strm->avail_in == 0) { |
333 | state->past = 1; /* tried to read past end */ | ||
333 | break; | 334 | break; |
335 | } | ||
334 | 336 | ||
335 | /* need output data -- for small len or new stream load up our output | 337 | /* need output data -- for small len or new stream load up our output |
336 | buffer */ | 338 | buffer */ |
@@ -437,6 +439,7 @@ int ZEXPORT gzungetc(c, file) | |||
437 | state->x.next = state->out + (state->size << 1) - 1; | 439 | state->x.next = state->out + (state->size << 1) - 1; |
438 | state->x.next[0] = c; | 440 | state->x.next[0] = c; |
439 | state->x.pos--; | 441 | state->x.pos--; |
442 | state->past = 0; | ||
440 | return c; | 443 | return c; |
441 | } | 444 | } |
442 | 445 | ||
@@ -458,6 +461,7 @@ int ZEXPORT gzungetc(c, file) | |||
458 | state->x.next--; | 461 | state->x.next--; |
459 | state->x.next[0] = c; | 462 | state->x.next[0] = c; |
460 | state->x.pos--; | 463 | state->x.pos--; |
464 | state->past = 0; | ||
461 | return c; | 465 | return c; |
462 | } | 466 | } |
463 | 467 | ||
@@ -499,9 +503,8 @@ char * ZEXPORT gzgets(file, buf, len) | |||
499 | if (state->x.have == 0 && gz_fetch(state) == -1) | 503 | if (state->x.have == 0 && gz_fetch(state) == -1) |
500 | return NULL; /* error */ | 504 | return NULL; /* error */ |
501 | if (state->x.have == 0) { /* end of file */ | 505 | if (state->x.have == 0) { /* end of file */ |
502 | if (buf == str) /* got bupkus */ | 506 | state->past = 1; /* read past end */ |
503 | return NULL; | 507 | break; /* return what we have */ |
504 | break; /* got something -- return it */ | ||
505 | } | 508 | } |
506 | 509 | ||
507 | /* look for end-of-line in current output buffer */ | 510 | /* look for end-of-line in current output buffer */ |
@@ -519,7 +522,9 @@ char * ZEXPORT gzgets(file, buf, len) | |||
519 | buf += n; | 522 | buf += n; |
520 | } while (left && eol == NULL); | 523 | } while (left && eol == NULL); |
521 | 524 | ||
522 | /* found end-of-line or out of space -- terminate string and return it */ | 525 | /* return terminated string, or if nothing, end of file */ |
526 | if (buf == str) | ||
527 | return NULL; | ||
523 | buf[0] = 0; | 528 | buf[0] = 0; |
524 | return str; | 529 | return str; |
525 | } | 530 | } |