From: Mark Adler Date: Thu, 24 Apr 2014 23:45:36 +0000 (-0400) Subject: Assure that gzoffset() is correct when appending. X-Git-Tag: 1.9.9-b1~793^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51bf318c94b6f15a2fafd09f5c3867f4f1d5d0c2;p=thirdparty%2Fzlib-ng.git 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. --- diff --git a/gzlib.c b/gzlib.c index 28732020e..8b23ecd98 100644 --- a/gzlib.c +++ b/gzlib.c @@ -189,8 +189,10 @@ local gzFile gz_open(const void *path, int fd, const char *mode) { free(state); 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 */ + } /* save the current position for rewinding (only if reading) */ if (state->mode == GZ_READ) {