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.
This commit is contained in:
parent
70e3b1ca56
commit
98f5779f42
5
gzguts.h
5
gzguts.h
@ -155,9 +155,10 @@ typedef struct {
|
|||||||
unsigned char *out; /* output buffer (double-sized when reading) */
|
unsigned char *out; /* output buffer (double-sized when reading) */
|
||||||
int direct; /* 0 if processing gzip, 1 if transparent */
|
int direct; /* 0 if processing gzip, 1 if transparent */
|
||||||
/* just for reading */
|
/* just for reading */
|
||||||
int eof; /* true if end of input file reached */
|
|
||||||
z_off64_t start; /* where the gzip data started, for rewinding */
|
|
||||||
int how; /* 0: get header, 1: copy, 2: decompress */
|
int how; /* 0: get header, 1: copy, 2: decompress */
|
||||||
|
z_off64_t start; /* where the gzip data started, for rewinding */
|
||||||
|
int eof; /* true if end of input file reached */
|
||||||
|
int past; /* true if read requested past end */
|
||||||
/* just for writing */
|
/* just for writing */
|
||||||
int level; /* compression level */
|
int level; /* compression level */
|
||||||
int strategy; /* compression strategy */
|
int strategy; /* compression strategy */
|
||||||
|
9
gzlib.c
9
gzlib.c
@ -78,6 +78,7 @@ local void gz_reset(state)
|
|||||||
state->x.have = 0; /* no output data available */
|
state->x.have = 0; /* no output data available */
|
||||||
if (state->mode == GZ_READ) { /* for reading ... */
|
if (state->mode == GZ_READ) { /* for reading ... */
|
||||||
state->eof = 0; /* not at end of file */
|
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->how = LOOK; /* look for gzip header */
|
||||||
}
|
}
|
||||||
state->seek = 0; /* no seek request pending */
|
state->seek = 0; /* no seek request pending */
|
||||||
@ -331,6 +332,7 @@ z_off64_t ZEXPORT gzseek64(file, offset, whence)
|
|||||||
return -1;
|
return -1;
|
||||||
state->x.have = 0;
|
state->x.have = 0;
|
||||||
state->eof = 0;
|
state->eof = 0;
|
||||||
|
state->past = 0;
|
||||||
state->seek = 0;
|
state->seek = 0;
|
||||||
gz_error(state, Z_OK, NULL);
|
gz_error(state, Z_OK, NULL);
|
||||||
state->strm.avail_in = 0;
|
state->strm.avail_in = 0;
|
||||||
@ -453,8 +455,7 @@ int ZEXPORT gzeof(file)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* return end-of-file state */
|
/* return end-of-file state */
|
||||||
return state->mode == GZ_READ ?
|
return state->mode == GZ_READ ? state->past : 0;
|
||||||
(state->eof && state->strm.avail_in == 0 && state->x.have == 0) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -- see zlib.h -- */
|
/* -- see zlib.h -- */
|
||||||
@ -491,8 +492,10 @@ void ZEXPORT gzclearerr(file)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* clear error and end-of-file */
|
/* clear error and end-of-file */
|
||||||
if (state->mode == GZ_READ)
|
if (state->mode == GZ_READ) {
|
||||||
state->eof = 0;
|
state->eof = 0;
|
||||||
|
state->past = 0;
|
||||||
|
}
|
||||||
gz_error(state, Z_OK, NULL);
|
gz_error(state, Z_OK, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
gzread.c
15
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 */
|
/* 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;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* need output data -- for small len or new stream load up our output
|
/* need output data -- for small len or new stream load up our output
|
||||||
buffer */
|
buffer */
|
||||||
@ -437,6 +439,7 @@ int ZEXPORT gzungetc(c, file)
|
|||||||
state->x.next = state->out + (state->size << 1) - 1;
|
state->x.next = state->out + (state->size << 1) - 1;
|
||||||
state->x.next[0] = c;
|
state->x.next[0] = c;
|
||||||
state->x.pos--;
|
state->x.pos--;
|
||||||
|
state->past = 0;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,6 +461,7 @@ int ZEXPORT gzungetc(c, file)
|
|||||||
state->x.next--;
|
state->x.next--;
|
||||||
state->x.next[0] = c;
|
state->x.next[0] = c;
|
||||||
state->x.pos--;
|
state->x.pos--;
|
||||||
|
state->past = 0;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,9 +503,8 @@ char * ZEXPORT gzgets(file, buf, len)
|
|||||||
if (state->x.have == 0 && gz_fetch(state) == -1)
|
if (state->x.have == 0 && gz_fetch(state) == -1)
|
||||||
return NULL; /* error */
|
return NULL; /* error */
|
||||||
if (state->x.have == 0) { /* end of file */
|
if (state->x.have == 0) { /* end of file */
|
||||||
if (buf == str) /* got bupkus */
|
state->past = 1; /* read past end */
|
||||||
return NULL;
|
break; /* return what we have */
|
||||||
break; /* got something -- return it */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* look for end-of-line in current output buffer */
|
/* look for end-of-line in current output buffer */
|
||||||
@ -519,7 +522,9 @@ char * ZEXPORT gzgets(file, buf, len)
|
|||||||
buf += n;
|
buf += n;
|
||||||
} while (left && eol == NULL);
|
} 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;
|
buf[0] = 0;
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user