vrshoot
diff libs/zlib/uncompr.c @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/zlib/uncompr.c Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,61 @@ 1.4 +/* uncompr.c -- decompress a memory buffer 1.5 + * Copyright (C) 1995-2003 Jean-loup Gailly. 1.6 + * For conditions of distribution and use, see copyright notice in zlib.h 1.7 + */ 1.8 + 1.9 +/* @(#) $Id$ */ 1.10 + 1.11 +#define ZLIB_INTERNAL 1.12 +#include "zlib.h" 1.13 + 1.14 +/* =========================================================================== 1.15 + Decompresses the source buffer into the destination buffer. sourceLen is 1.16 + the byte length of the source buffer. Upon entry, destLen is the total 1.17 + size of the destination buffer, which must be large enough to hold the 1.18 + entire uncompressed data. (The size of the uncompressed data must have 1.19 + been saved previously by the compressor and transmitted to the decompressor 1.20 + by some mechanism outside the scope of this compression library.) 1.21 + Upon exit, destLen is the actual size of the compressed buffer. 1.22 + This function can be used to decompress a whole file at once if the 1.23 + input file is mmap'ed. 1.24 + 1.25 + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 1.26 + enough memory, Z_BUF_ERROR if there was not enough room in the output 1.27 + buffer, or Z_DATA_ERROR if the input data was corrupted. 1.28 +*/ 1.29 +int ZEXPORT uncompress (dest, destLen, source, sourceLen) 1.30 + Bytef *dest; 1.31 + uLongf *destLen; 1.32 + const Bytef *source; 1.33 + uLong sourceLen; 1.34 +{ 1.35 + z_stream stream; 1.36 + int err; 1.37 + 1.38 + stream.next_in = (Bytef*)source; 1.39 + stream.avail_in = (uInt)sourceLen; 1.40 + /* Check for source > 64K on 16-bit machine: */ 1.41 + if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 1.42 + 1.43 + stream.next_out = dest; 1.44 + stream.avail_out = (uInt)*destLen; 1.45 + if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 1.46 + 1.47 + stream.zalloc = (alloc_func)0; 1.48 + stream.zfree = (free_func)0; 1.49 + 1.50 + err = inflateInit(&stream); 1.51 + if (err != Z_OK) return err; 1.52 + 1.53 + err = inflate(&stream, Z_FINISH); 1.54 + if (err != Z_STREAM_END) { 1.55 + inflateEnd(&stream); 1.56 + if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 1.57 + return Z_DATA_ERROR; 1.58 + return err; 1.59 + } 1.60 + *destLen = stream.total_out; 1.61 + 1.62 + err = inflateEnd(&stream); 1.63 + return err; 1.64 +}