ยปCore Development>Code coverage>Modules/zlib/uncompr.c

Python code coverage for Modules/zlib/uncompr.c

#countcontent
1n/a/* uncompr.c -- decompress a memory buffer
2n/a * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler
3n/a * For conditions of distribution and use, see copyright notice in zlib.h
4n/a */
5n/a
6n/a/* @(#) $Id$ */
7n/a
8n/a#define ZLIB_INTERNAL
9n/a#include "zlib.h"
10n/a
11n/a/* ===========================================================================
12n/a Decompresses the source buffer into the destination buffer. *sourceLen is
13n/a the byte length of the source buffer. Upon entry, *destLen is the total size
14n/a of the destination buffer, which must be large enough to hold the entire
15n/a uncompressed data. (The size of the uncompressed data must have been saved
16n/a previously by the compressor and transmitted to the decompressor by some
17n/a mechanism outside the scope of this compression library.) Upon exit,
18n/a *destLen is the size of the decompressed data and *sourceLen is the number
19n/a of source bytes consumed. Upon return, source + *sourceLen points to the
20n/a first unused input byte.
21n/a
22n/a uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
23n/a memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
24n/a Z_DATA_ERROR if the input data was corrupted, including if the input data is
25n/a an incomplete zlib stream.
26n/a*/
27n/aint ZEXPORT uncompress2 (dest, destLen, source, sourceLen)
28n/a Bytef *dest;
29n/a uLongf *destLen;
30n/a const Bytef *source;
31n/a uLong *sourceLen;
32n/a{
33n/a z_stream stream;
34n/a int err;
35n/a const uInt max = (uInt)-1;
36n/a uLong len, left;
37n/a Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
38n/a
39n/a len = *sourceLen;
40n/a if (*destLen) {
41n/a left = *destLen;
42n/a *destLen = 0;
43n/a }
44n/a else {
45n/a left = 1;
46n/a dest = buf;
47n/a }
48n/a
49n/a stream.next_in = (z_const Bytef *)source;
50n/a stream.avail_in = 0;
51n/a stream.zalloc = (alloc_func)0;
52n/a stream.zfree = (free_func)0;
53n/a stream.opaque = (voidpf)0;
54n/a
55n/a err = inflateInit(&stream);
56n/a if (err != Z_OK) return err;
57n/a
58n/a stream.next_out = dest;
59n/a stream.avail_out = 0;
60n/a
61n/a do {
62n/a if (stream.avail_out == 0) {
63n/a stream.avail_out = left > (uLong)max ? max : (uInt)left;
64n/a left -= stream.avail_out;
65n/a }
66n/a if (stream.avail_in == 0) {
67n/a stream.avail_in = len > (uLong)max ? max : (uInt)len;
68n/a len -= stream.avail_in;
69n/a }
70n/a err = inflate(&stream, Z_NO_FLUSH);
71n/a } while (err == Z_OK);
72n/a
73n/a *sourceLen -= len + stream.avail_in;
74n/a if (dest != buf)
75n/a *destLen = stream.total_out;
76n/a else if (stream.total_out && err == Z_BUF_ERROR)
77n/a left = 1;
78n/a
79n/a inflateEnd(&stream);
80n/a return err == Z_STREAM_END ? Z_OK :
81n/a err == Z_NEED_DICT ? Z_DATA_ERROR :
82n/a err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
83n/a err;
84n/a}
85n/a
86n/aint ZEXPORT uncompress (dest, destLen, source, sourceLen)
87n/a Bytef *dest;
88n/a uLongf *destLen;
89n/a const Bytef *source;
90n/a uLong sourceLen;
91n/a{
92n/a return uncompress2(dest, destLen, source, &sourceLen);
93n/a}