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