dbf-halloween2015

annotate libs/zlib/uncompr.c @ 1:c3f5c32cb210

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