The gzread() helper does not return an error if a file is truncated.
This is done to allow reading a file that that is being concurrently
written.
As workaround, get the error code if an EOF is reached and treat
Z_BUF_ERROR as read error.
static ssize_t cookie_gzread(void *cookie, char *buf, size_t nbytes)
{
- return gzread((gzFile)cookie, buf, nbytes);
+ ssize_t r = gzread((gzFile)cookie, buf, nbytes);
+ if (r == 0)
+ {
+ int err = 0;
+ gzerror((gzFile)cookie, &err);
+ if (err == Z_BUF_ERROR)
+ r = -1;
+ }
+ return r;
}
static ssize_t cookie_gzwrite(void *cookie, const char *buf, size_t nbytes)