annotate src/zlib-1.2.7/uncompr.c @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents e13257ea84a4
children
rev   line source
Chris@4 1 /* uncompr.c -- decompress a memory buffer
Chris@4 2 * Copyright (C) 1995-2003, 2010 Jean-loup Gailly.
Chris@4 3 * For conditions of distribution and use, see copyright notice in zlib.h
Chris@4 4 */
Chris@4 5
Chris@4 6 /* @(#) $Id$ */
Chris@4 7
Chris@4 8 #define ZLIB_INTERNAL
Chris@4 9 #include "zlib.h"
Chris@4 10
Chris@4 11 /* ===========================================================================
Chris@4 12 Decompresses the source buffer into the destination buffer. sourceLen is
Chris@4 13 the byte length of the source buffer. Upon entry, destLen is the total
Chris@4 14 size of the destination buffer, which must be large enough to hold the
Chris@4 15 entire uncompressed data. (The size of the uncompressed data must have
Chris@4 16 been saved previously by the compressor and transmitted to the decompressor
Chris@4 17 by some mechanism outside the scope of this compression library.)
Chris@4 18 Upon exit, destLen is the actual size of the compressed buffer.
Chris@4 19
Chris@4 20 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
Chris@4 21 enough memory, Z_BUF_ERROR if there was not enough room in the output
Chris@4 22 buffer, or Z_DATA_ERROR if the input data was corrupted.
Chris@4 23 */
Chris@4 24 int ZEXPORT uncompress (dest, destLen, source, sourceLen)
Chris@4 25 Bytef *dest;
Chris@4 26 uLongf *destLen;
Chris@4 27 const Bytef *source;
Chris@4 28 uLong sourceLen;
Chris@4 29 {
Chris@4 30 z_stream stream;
Chris@4 31 int err;
Chris@4 32
Chris@4 33 stream.next_in = (Bytef*)source;
Chris@4 34 stream.avail_in = (uInt)sourceLen;
Chris@4 35 /* Check for source > 64K on 16-bit machine: */
Chris@4 36 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
Chris@4 37
Chris@4 38 stream.next_out = dest;
Chris@4 39 stream.avail_out = (uInt)*destLen;
Chris@4 40 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
Chris@4 41
Chris@4 42 stream.zalloc = (alloc_func)0;
Chris@4 43 stream.zfree = (free_func)0;
Chris@4 44
Chris@4 45 err = inflateInit(&stream);
Chris@4 46 if (err != Z_OK) return err;
Chris@4 47
Chris@4 48 err = inflate(&stream, Z_FINISH);
Chris@4 49 if (err != Z_STREAM_END) {
Chris@4 50 inflateEnd(&stream);
Chris@4 51 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
Chris@4 52 return Z_DATA_ERROR;
Chris@4 53 return err;
Chris@4 54 }
Chris@4 55 *destLen = stream.total_out;
Chris@4 56
Chris@4 57 err = inflateEnd(&stream);
Chris@4 58 return err;
Chris@4 59 }