annotate src/zlib-1.2.8/uncompr.c @ 56:af97cad61ff0

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