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