istereo

annotate libs/zlib/uncompr.c @ 27:fd39c0198935

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