author | zautrix <zautrix> | 2004-10-19 20:16:14 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-19 20:16:14 (UTC) |
commit | eca49bb06a71980ef61d078904573f25890fc7f2 (patch) (unidiff) | |
tree | c5338e3b12430248979a9ac2c1c7e6646ea9ecdf /pwmanager/libcrypt/zlib/uncompr.c | |
parent | 53cc32b6e7b1f672bf91b2baf2df6c1e8baf3e0a (diff) | |
download | kdepimpi-eca49bb06a71980ef61d078904573f25890fc7f2.zip kdepimpi-eca49bb06a71980ef61d078904573f25890fc7f2.tar.gz kdepimpi-eca49bb06a71980ef61d078904573f25890fc7f2.tar.bz2 |
Initial revision
Diffstat (limited to 'pwmanager/libcrypt/zlib/uncompr.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | pwmanager/libcrypt/zlib/uncompr.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/pwmanager/libcrypt/zlib/uncompr.c b/pwmanager/libcrypt/zlib/uncompr.c new file mode 100644 index 0000000..a287714 --- a/dev/null +++ b/pwmanager/libcrypt/zlib/uncompr.c | |||
@@ -0,0 +1,58 @@ | |||
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.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 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) | ||
26 | Bytef *dest; | ||
27 | uLongf *destLen; | ||
28 | const Bytef *source; | ||
29 | uLong sourceLen; | ||
30 | { | ||
31 | z_stream stream; | ||
32 | int err; | ||
33 | |||
34 | stream.next_in = (Bytef*)source; | ||
35 | stream.avail_in = (uInt)sourceLen; | ||
36 | /* Check for source > 64K on 16-bit machine: */ | ||
37 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; | ||
38 | |||
39 | stream.next_out = dest; | ||
40 | stream.avail_out = (uInt)*destLen; | ||
41 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; | ||
42 | |||
43 | stream.zalloc = (alloc_func)0; | ||
44 | stream.zfree = (free_func)0; | ||
45 | |||
46 | err = inflateInit(&stream); | ||
47 | if (err != Z_OK) return err; | ||
48 | |||
49 | err = inflate(&stream, Z_FINISH); | ||
50 | if (err != Z_STREAM_END) { | ||
51 | inflateEnd(&stream); | ||
52 | return err == Z_OK ? Z_BUF_ERROR : err; | ||
53 | } | ||
54 | *destLen = stream.total_out; | ||
55 | |||
56 | err = inflateEnd(&stream); | ||
57 | return err; | ||
58 | } | ||