package/utils/fritz-tools/src/fritz_cal_extract.c
/* Decompress from file source to file dest until stream ends or EOF.
   inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
   allocated for processing, Z_DATA_ERROR if the deflate data is
   invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
   the version of the library linked do not match, or Z_ERRNO if there
   is an error reading or writing the files. */
Decompress from file source to file dest until stream ends or EOF.
inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_DATA_ERROR if the deflate data is
invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
the version of the library linked do not match, or Z_ERRNO if there
is an error reading or writing the files.
Decompress from file source to file dest until stream ends or EOF . inf () returns Z_OK on success Z_MEM_ERROR if memory could not be allocated for processing Z_DATA_ERROR if the deflate data is invalid or incomplete Z_VERSION_ERROR if the version of zlib . h and the version of the library linked do not match or Z_ERRNO if there is an error reading or writing the files .
static int inf(FILE *source, FILE *dest, size_t limit, size_t skip)
{
    int ret;
    size_t have;
    z_stream strm;
    unsigned char in[CHUNK];
    unsigned char out[CHUNK];
    strm.zalloc = Z_NULL;
    strm.zfree = Z_NULL;
    strm.opaque = Z_NULL;
    strm.avail_in = 0;
    strm.next_in = Z_NULL;
    ret = inflateInit(&strm);
    if (ret != Z_OK)
        return ret;
    do {
        strm.avail_in = fread(in, 1, CHUNK, source);
        if (ferror(source)) {
            (void)inflateEnd(&strm);
            return Z_ERRNO;
        }
        if (strm.avail_in == 0)
            break;
        strm.next_in = in;
        do {
            strm.avail_out = CHUNK;
            strm.next_out = out;
            ret = inflate(&strm, Z_NO_FLUSH);
            assert(ret != Z_STREAM_ERROR);  
            switch (ret) {
            case Z_NEED_DICT:
                ret = Z_DATA_ERROR;     
            case Z_DATA_ERROR:
            case Z_MEM_ERROR:
                (void)inflateEnd(&strm);
                return ret;
            }
            have = special_min(limit, CHUNK - strm.avail_out) - skip;
            if (fwrite(&out[skip], have, 1, dest) != 1 || ferror(dest)) {
                (void)inflateEnd(&strm);
                return Z_ERRNO;
            }
	    skip = 0;
	    limit -= have;
        } while (strm.avail_out == 0 && limit > 0);
    } while (ret != Z_STREAM_END && limit > 0);
    (void)inflateEnd(&strm);
    return (limit == 0 ? Z_OK : (ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR));
}
static int inf ( FILE * source , FILE * dest , size_t limit , size_t skip ) { int ret ; size_t have ; z_stream strm ; unsigned char in [ CHUNK ] ; unsigned char out [ CHUNK ] ; strm . zalloc = Z_NULL ; strm . zfree = Z_NULL ; strm . opaque = Z_NULL ; strm . avail_in = 0 ; strm . next_in = Z_NULL ; ret = inflateInit ( & strm ) ; if ( ret != Z_OK ) return ret ; do { strm . avail_in = fread ( in , 1 , CHUNK , source ) ; if ( ferror ( source ) ) { ( void ) inflateEnd ( & strm ) ; return Z_ERRNO ; } if ( strm . avail_in == 0 ) break ; strm . next_in = in ; do { strm . avail_out = CHUNK ; strm . next_out = out ; ret = inflate ( & strm , Z_NO_FLUSH ) ; assert ( ret != Z_STREAM_ERROR ) ; switch ( ret ) { case Z_NEED_DICT : ret = Z_DATA_ERROR ; case Z_DATA_ERROR : case Z_MEM_ERROR : ( void ) inflateEnd ( & strm ) ; return ret ; } have = special_min ( limit , CHUNK - strm . avail_out ) - skip ; if ( fwrite ( & out [ skip ] , have , 1 , dest ) != 1 || ferror ( dest ) ) { ( void ) inflateEnd ( & strm ) ; return Z_ERRNO ; } skip = 0 ; limit -= have ; } while ( strm . avail_out == 0 && limit > 0 ) ; } while ( ret != Z_STREAM_END && limit > 0 ) ; ( void ) inflateEnd ( & strm ) ; return ( limit == 0 ? Z_OK : ( ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR ) ) ; }
Decompress from file source to file dest until stream ends or EOF.
Decompress from file source to file dest until stream ends or EOF .
/* allocate inflate state */ /* decompress until deflate stream ends or end of file */ /* run inflate() on input until output buffer not full */ /* state not clobbered */ /* and fall through */ /* done when inflate() says it's done */ /* clean up and return */