Dependencies:   emwin_lib

Fork of DMemWin by Embedded Artists

Committer:
destinyXfate
Date:
Thu Jun 02 04:55:08 2016 +0000
Revision:
4:20387dbf7ecf
Parent:
2:0e2ef1edf01b
;

Who changed what in which revision?

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