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