]> git.saurik.com Git - wxWidgets.git/blame - src/zlib/uncompr.c
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / src / zlib / uncompr.c
CommitLineData
c801d85f 1/* uncompr.c -- decompress a memory buffer
772513d8 2 * Copyright (C) 1995-2003, 2010 Jean-loup Gailly.
e6ebb514 3 * For conditions of distribution and use, see copyright notice in zlib.h
c801d85f
KB
4 */
5
c801d85f 6
51dbdf87
VS
7#define ZLIB_INTERNAL
8#include "zlib.h"
c801d85f
KB
9
10/* ===========================================================================
11 Decompresses the source buffer into the destination buffer. sourceLen is
12 the byte length of the source buffer. Upon entry, destLen is the total
13 size of the destination buffer, which must be large enough to hold the
14 entire uncompressed data. (The size of the uncompressed data must have
15 been saved previously by the compressor and transmitted to the decompressor
16 by some mechanism outside the scope of this compression library.)
17 Upon exit, destLen is the actual size of the compressed buffer.
c801d85f
KB
18
19 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
20 enough memory, Z_BUF_ERROR if there was not enough room in the output
21 buffer, or Z_DATA_ERROR if the input data was corrupted.
22*/
23int ZEXPORT uncompress (dest, destLen, source, sourceLen)
24 Bytef *dest;
25 uLongf *destLen;
26 const Bytef *source;
27 uLong sourceLen;
28{
29 z_stream stream;
30 int err;
31
772513d8 32 stream.next_in = (z_const Bytef *)source;
c801d85f
KB
33 stream.avail_in = (uInt)sourceLen;
34 /* Check for source > 64K on 16-bit machine: */
35 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
36
37 stream.next_out = dest;
38 stream.avail_out = (uInt)*destLen;
39 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
40
41 stream.zalloc = (alloc_func)0;
42 stream.zfree = (free_func)0;
43
44 err = inflateInit(&stream);
45 if (err != Z_OK) return err;
46
47 err = inflate(&stream, Z_FINISH);
48 if (err != Z_STREAM_END) {
49 inflateEnd(&stream);
51dbdf87
VS
50 if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
51 return Z_DATA_ERROR;
52 return err;
c801d85f
KB
53 }
54 *destLen = stream.total_out;
55
56 err = inflateEnd(&stream);
57 return err;
58}