summaryrefslogtreecommitdiff
path: root/gzlib.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2014-04-24 19:45:36 -0400
committerMark Adler <madler@alumni.caltech.edu>2014-04-24 19:45:36 -0400
commit72c70060d8312cff06754779188d8adeb974f18c (patch)
tree09f276cf9d3c3c33ce91fec1807c29b3891010ec /gzlib.c
parent799c87c0d8fc5af306f8c7a160dfd3d75746c2ce (diff)
downloadzlib-72c70060d8312cff06754779188d8adeb974f18c.tar.gz
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 fae202e..ced2cb8 100644
--- 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) {