]> git.lizzy.rs Git - zlib.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)
committerMark Adler <madler@alumni.caltech.edu>
Thu, 24 Apr 2014 23:45:36 +0000 (19:45 -0400)
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 fae202ef8905a3c99e4b71d756a45d55f9b1c163..ced2cb8ba74096377051f98892479ee95b537c73 100644 (file)
--- a/gzlib.c
+++ b/gzlib.c
@@ -248,8 +248,10 @@ local gzFile gz_open(path, fd, 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) {