summaryrefslogtreecommitdiff
path: root/gzlib.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2014-04-24 19:45:36 -0400
committerHans Kristian Rosbach <hk-git@circlestorm.org>2015-11-03 18:53:46 +0100
commit51bf318c94b6f15a2fafd09f5c3867f4f1d5d0c2 (patch)
tree8e16ab68f0ab0754a2c9cdd95a46f436e5096245 /gzlib.c
parent3c7b16a1e3878e79b99004c526152fef8e02bce8 (diff)
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.
Diffstat (limited to 'gzlib.c')
-rw-r--r--gzlib.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/gzlib.c b/gzlib.c
index 2873202..8b23ecd 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) {