/* uncompr.c -- decompress a memory buffer1* Copyright (C) 1995-2003 Jean-loup Gailly.2* For conditions of distribution and use, see copyright notice in zlib.h3*/45/* @(#) $Id$ */67#define ZLIB_INTERNAL8#include "zlib.h"910/* ===========================================================================11Decompresses the source buffer into the destination buffer. sourceLen is12the byte length of the source buffer. Upon entry, destLen is the total13size of the destination buffer, which must be large enough to hold the14entire uncompressed data. (The size of the uncompressed data must have15been saved previously by the compressor and transmitted to the decompressor16by some mechanism outside the scope of this compression library.)17Upon exit, destLen is the actual size of the compressed buffer.18This function can be used to decompress a whole file at once if the19input file is mmap'ed.2021uncompress returns Z_OK if success, Z_MEM_ERROR if there was not22enough memory, Z_BUF_ERROR if there was not enough room in the output23buffer, or Z_DATA_ERROR if the input data was corrupted.24*/25int ZEXPORT uncompress (dest, destLen, source, sourceLen)26Bytef *dest;27uLongf *destLen;28const Bytef *source;29uLong sourceLen;30{31z_stream stream;32int err;3334stream.next_in = (Bytef*)source;35stream.avail_in = (uInt)sourceLen;36/* Check for source > 64K on 16-bit machine: */37if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;3839stream.next_out = dest;40stream.avail_out = (uInt)*destLen;41if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;4243stream.zalloc = (alloc_func)0;44stream.zfree = (free_func)0;4546err = inflateInit(&stream);47if (err != Z_OK) return err;4849err = inflate(&stream, Z_FINISH);50if (err != Z_STREAM_END) {51inflateEnd(&stream);52if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))53return Z_DATA_ERROR;54return err;55}56*destLen = stream.total_out;5758err = inflateEnd(&stream);59return err;60}616263