]> git.lizzy.rs Git - zlib.git/commitdiff
Fix gzclose() to return the actual error last encountered.
authorMark Adler <madler@alumni.caltech.edu>
Sat, 1 Oct 2011 05:19:12 +0000 (22:19 -0700)
committerMark Adler <madler@alumni.caltech.edu>
Sat, 1 Oct 2011 05:19:12 +0000 (22:19 -0700)
gzwrite.c
zlib.h

index d08f30921cfbad75429b48545e8d3f7b35e84356..8eeca4ed2e6525c575298c44a2750c6e5c65fe33 100644 (file)
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -504,7 +504,7 @@ int ZEXPORT gzsetparams(file, level, strategy)
 int ZEXPORT gzclose_w(file)
     gzFile file;
 {
-    int ret = 0;
+    int ret = Z_OK;
     gz_statep state;
 
     /* get internal structure */
@@ -519,17 +519,20 @@ int ZEXPORT gzclose_w(file)
     /* check for seek request */
     if (state->seek) {
         state->seek = 0;
-        ret += gz_zero(state, state->skip);
+        if (gz_zero(state, state->skip) == -1)
+            ret = state->err;
     }
 
     /* flush, free memory, and close file */
-    ret += gz_comp(state, Z_FINISH);
+    if (gz_comp(state, Z_FINISH) == -1)
+        ret = state->err;
     (void)deflateEnd(&(state->strm));
     free(state->out);
     free(state->in);
     gz_error(state, Z_OK, NULL);
     free(state->path);
-    ret += close(state->fd);
+    if (close(state->fd) == -1)
+        ret = Z_ERRNO;
     free(state);
-    return ret ? Z_ERRNO : Z_OK;
+    return ret;
 }
diff --git a/zlib.h b/zlib.h
index d358a62dc4f0e4fd8b2a7f1c1b265a84466a876c..16b20ce8393347e2712407ccf6cb4de2c1ae1428 100644 (file)
--- a/zlib.h
+++ b/zlib.h
@@ -1446,7 +1446,7 @@ 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, or Z_OK on success.
+   file operation error, Z_MEM_ERROR if out of memory, or Z_OK on success.
 */
 
 ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));