aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gzguts.h5
-rw-r--r--gzlib.c9
-rw-r--r--gzread.c15
3 files changed, 19 insertions, 10 deletions
diff --git a/gzguts.h b/gzguts.h
index eefdca0..07c7ac3 100644
--- a/gzguts.h
+++ b/gzguts.h
@@ -155,9 +155,10 @@ typedef struct {
155 unsigned char *out; /* output buffer (double-sized when reading) */ 155 unsigned char *out; /* output buffer (double-sized when reading) */
156 int direct; /* 0 if processing gzip, 1 if transparent */ 156 int direct; /* 0 if processing gzip, 1 if transparent */
157 /* just for reading */ 157 /* just for reading */
158 int eof; /* true if end of input file reached */
159 z_off64_t start; /* where the gzip data started, for rewinding */
160 int how; /* 0: get header, 1: copy, 2: decompress */ 158 int how; /* 0: get header, 1: copy, 2: decompress */
159 z_off64_t start; /* where the gzip data started, for rewinding */
160 int eof; /* true if end of input file reached */
161 int past; /* true if read requested past end */
161 /* just for writing */ 162 /* just for writing */
162 int level; /* compression level */ 163 int level; /* compression level */
163 int strategy; /* compression strategy */ 164 int strategy; /* compression strategy */
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)
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
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)
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}