diff options
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 | } |