Assure that gzoffset() is correct when appending.

An open() with O_APPEND followed by an lseek() to determine the
position will return zero for a non-empty file, even though the
next write will start at the end of the file.  This commit works
around that by doing an lseek() to the end when appending.
This commit is contained in:
Mark Adler 2014-04-24 19:45:36 -04:00
parent 799c87c0d8
commit 72c70060d8

View File

@ -248,8 +248,10 @@ local gzFile gz_open(path, fd, mode)
free(state); free(state);
return NULL; return NULL;
} }
if (state->mode == GZ_APPEND) if (state->mode == GZ_APPEND) {
LSEEK(state->fd, 0, SEEK_END); /* so gzoffset() is correct */
state->mode = GZ_WRITE; /* simplify later checks */ state->mode = GZ_WRITE; /* simplify later checks */
}
/* save the current position for rewinding (only if reading) */ /* save the current position for rewinding (only if reading) */
if (state->mode == GZ_READ) { if (state->mode == GZ_READ) {