Example #1
0
static int
zf_read(struct open_file *f, void *buf, size_t size, size_t *resid)
{
    struct z_file	*zf = (struct z_file *)f->f_fsdata;
    int			error;

    zf->zf_zstream.next_out = buf;			/* where and how much */
    zf->zf_zstream.avail_out = size;

    while (zf->zf_zstream.avail_out && zf->zf_endseen == 0) {
        if ((zf->zf_zstream.avail_in == 0) && (zf_fill(zf) == -1)) {
            printf("zf_read: fill error\n");
            return(EIO);
        }
        if (zf->zf_zstream.avail_in == 0) {		/* oops, unexpected EOF */
            printf("zf_read: unexpected EOF\n");
            if (zf->zf_zstream.avail_out == size)
                return(EIO);
            break;
        }

        error = inflate(&zf->zf_zstream, Z_SYNC_FLUSH);	/* decompression pass */
        if (error == Z_STREAM_END) {			/* EOF, all done */
            zf->zf_endseen = 1;
            break;
        }
        if (error != Z_OK) {				/* argh, decompression error */
            printf("inflate: %s\n", zf->zf_zstream.msg);
            return(EIO);
        }
    }
    if (resid != NULL)
        *resid = zf->zf_zstream.avail_out;
    return(0);
}
Example #2
0
/*
 * Adapted from get_byte/check_header in libz
 *
 * Returns 0 if the header is OK, nonzero if not.
 */
static int
get_byte(struct z_file *zf)
{
    if ((zf->zf_zstream.avail_in == 0) && (zf_fill(zf) == -1))
        return(-1);
    zf->zf_zstream.avail_in--;
    return(*(zf->zf_zstream.next_in)++);
}