]> git.lizzy.rs Git - zlib.git/commitdiff
Document gzread() capability to read concurrently written files.
authorMark Adler <madler@alumni.caltech.edu>
Wed, 14 Dec 2011 12:21:00 +0000 (04:21 -0800)
committerMark Adler <madler@alumni.caltech.edu>
Wed, 14 Dec 2011 12:21:00 +0000 (04:21 -0800)
Also since gzread() will no longer return an error for an incomplete
gzip file, have gzclose() return an error if the last gzread() ended
in the middle of a gzip stream.

gzread.c
zlib.h

index 4bbbf52e460e4a9af089962908efca25dba7d72e..09e586366fc7edf9db6ca1d512e72a4eb78f8fa8 100644 (file)
--- a/gzread.c
+++ b/gzread.c
@@ -553,7 +553,7 @@ int ZEXPORT gzdirect(file)
 int ZEXPORT gzclose_r(file)
     gzFile file;
 {
-    int ret;
+    int ret, err;
     gz_statep state;
 
     /* get internal structure */
@@ -571,9 +571,10 @@ int ZEXPORT gzclose_r(file)
         free(state->out);
         free(state->in);
     }
+    err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
     gz_error(state, Z_OK, NULL);
     free(state->path);
     ret = close(state->fd);
     free(state);
-    return ret ? Z_ERRNO : Z_OK;
+    return ret ? Z_ERRNO : err;
 }
diff --git a/zlib.h b/zlib.h
index 1ee04e9e5b86484f2722e637133a2101b33cdf5b..7068d50f393c096e8b75f4d230623ed7696fc371 100644 (file)
--- a/zlib.h
+++ b/zlib.h
@@ -1297,6 +1297,18 @@ ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
    If something other than a gzip stream is encountered after a gzip stream,
    that remaining trailing garbage is ignored (and no error is returned).
 
+     gzread can be used to read a gzip file that is being concurrently written.
+   Upon reaching the end of the input, gzread will return with the available
+   data.  If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
+   gzclearerr can be used to clear the end of file indicator in order to permit
+   gzread to be tried again.  Z_OK indicates that a gzip stream was completed
+   on the last gzread.  Z_BUF_ERROR indicates that the input file ended in the
+   middle of a gzip stream.  Note that gzread does not return -1 in the event
+   of an incomplete gzip stream.  This error is deferred until gzclose(), which
+   will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
+   stream.  Alternatively, gzerror can be used before gzclose to detect this
+   case.
+
      gzread returns the number of uncompressed bytes actually read, less than
    len for end of file, or -1 for error.
 */
@@ -1480,7 +1492,8 @@ ZEXTERN int ZEXPORT    gzclose OF((gzFile file));
    must not be called more than once on the same allocation.
 
      gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
-   file operation error, Z_MEM_ERROR if out of memory, or Z_OK on success.
+   file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
+   last read ended in the middle of a gzip stream, or Z_OK on success.
 */
 
 ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));