]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Assure that gzoffset() is correct when appending.
authorMark Adler <madler@alumni.caltech.edu>
Thu, 24 Apr 2014 23:45:36 +0000 (19:45 -0400)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Tue, 3 Nov 2015 17:53:46 +0000 (18:53 +0100)
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.

gzlib.c

diff --git a/gzlib.c b/gzlib.c
index 28732020eaefff12561591c1fb5acb24baa4b681..8b23ecd98661794529bb78445b6603a0d6777463 100644 (file)
--- 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) {