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