From 5ad116abdad08c49b9ab20d748550eecd2c1d96d Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Mon, 26 Sep 2011 00:57:26 -0700 Subject: Allow gzread() and related to continue after gzclearerr(). Before this fix, gzread() would lose data if a premature end of file was encountered. This prevented gzread() from being used on a file that was being written concurrently. Now gzread() returns all of the data it has available before indicating a premature end of file. This also changes the error returned on a premature end of file from Z_DATA_ERROR to Z_BUF_ERROR. This allows the user to determine if the error is recoverable, which it is if Z_BUF_ERROR is returned. If a Z_DATA_ERROR is returned, then the error is not recoverable. This patch replaces the functionality of a previous patch that fixed reading through an empty gzip stream in a concatenation of gzip streams. To implement this fix, a noticeable rewrite of gzread.c was needed. The patch has the added advantage of using inflate's gzip processing instead of replicating the functionality in gzread.c. This makes the gz code a little simpler. --- gzlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gzlib.c') diff --git a/gzlib.c b/gzlib.c index d16b249..e8cb479 100644 --- a/gzlib.c +++ b/gzlib.c @@ -247,8 +247,8 @@ int ZEXPORT gzbuffer(file, size) return -1; /* check and set requested size */ - if (size == 0) - return -1; + if (size < 2) + size = 2; /* need two bytes to check magic header */ state->want = size; return 0; } -- cgit v1.2.1