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