4737N/A
4737N/A/* uncompr.c -- decompress a memory buffer
4737N/A * Copyright (C) 1995-2002 Jean-loup Gailly.
4737N/A * For conditions of distribution and use, see copyright notice in zlib.h
4737N/A */
4737N/A
4737N/A
4737N/A#include "zlib.h"
4737N/A
4737N/A/* ===========================================================================
4737N/A Decompresses the source buffer into the destination buffer. sourceLen is
4737N/A the byte length of the source buffer. Upon entry, destLen is the total
4737N/A size of the destination buffer, which must be large enough to hold the
4737N/A entire uncompressed data. (The size of the uncompressed data must have
4737N/A been saved previously by the compressor and transmitted to the decompressor
4737N/A by some mechanism outside the scope of this compression library.)
4737N/A Upon exit, destLen is the actual size of the compressed buffer.
4737N/A This function can be used to decompress a whole file at once if the
4737N/A input file is mmap'ed.
4737N/A
4737N/A uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
4737N/A enough memory, Z_BUF_ERROR if there was not enough room in the output
5336N/A buffer, or Z_DATA_ERROR if the input data was corrupted.
4737N/A*/
5716N/Aint ZEXPORT uncompress (dest, destLen, source, sourceLen)
5716N/A Bytef *dest;
5680N/A uLongf *destLen;
4737N/A const Bytef *source;
4737N/A uLong sourceLen;
4737N/A{
5363N/A z_stream stream;
4737N/A int err;
4737N/A
5363N/A stream.next_in = (Bytef*)source;
4737N/A stream.avail_in = (uInt)sourceLen;
4737N/A /* Check for source > 64K on 16-bit machine: */
4737N/A if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
5363N/A
4737N/A stream.next_out = dest;
6011N/A stream.avail_out = (uInt)*destLen;
6011N/A if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
6011N/A
6011N/A stream.zalloc = (alloc_func)0;
6011N/A stream.zfree = (free_func)0;
6011N/A
6011N/A err = inflateInit(&stream);
6011N/A if (err != Z_OK) return err;
5680N/A
5680N/A err = inflate(&stream, Z_FINISH);
5680N/A if (err != Z_STREAM_END) {
4737N/A inflateEnd(&stream);
4737N/A return err == Z_OK ? Z_BUF_ERROR : err;
4737N/A }
4737N/A *destLen = stream.total_out;
5680N/A
5690N/A err = inflateEnd(&stream);
5690N/A return err;
5690N/A}
5690N/A