]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/zlib/uncompr.c
0. wxExecute() with IO redirection now works again (but the real fix is
[wxWidgets.git] / src / zlib / uncompr.c
... / ...
CommitLineData
1/* uncompr.c -- decompress a memory buffer
2 * Copyright (C) 1995-2002 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#include "../zlib/zlib.h"
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.
18 This function can be used to decompress a whole file at once if the
19 input file is mmap'ed.
20
21 uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
22 enough memory, Z_BUF_ERROR if there was not enough room in the output
23 buffer, or Z_DATA_ERROR if the input data was corrupted.
24*/
25#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */
26int ZEXPORT uncompress (Bytef* dest, uLongf* destLen, const Bytef* source, uLong sourceLen)
27#else
28int ZEXPORT uncompress (dest, destLen, source, sourceLen)
29 Bytef *dest;
30 uLongf *destLen;
31 const Bytef *source;
32 uLong sourceLen;
33#endif
34{
35 z_stream stream;
36 int err;
37
38 stream.next_in = (Bytef*)source;
39 stream.avail_in = (uInt)sourceLen;
40 /* Check for source > 64K on 16-bit machine: */
41 if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
42
43 stream.next_out = dest;
44 stream.avail_out = (uInt)*destLen;
45 if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
46
47 stream.zalloc = (alloc_func)0;
48 stream.zfree = (free_func)0;
49
50 err = inflateInit(&stream);
51 if (err != Z_OK) return err;
52
53 err = inflate(&stream, Z_FINISH);
54 if (err != Z_STREAM_END) {
55 inflateEnd(&stream);
56 return err == Z_OK ? Z_BUF_ERROR : err;
57 }
58 *destLen = stream.total_out;
59
60 err = inflateEnd(&stream);
61 return err;
62}