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