File indexing completed on 2025-05-11 08:24:11
0001
0002
0003
0004
0005
0006
0007
0008 #define ZLIB_INTERNAL
0009 #include "zlib.h"
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 int ZEXPORT uncompress2(dest, destLen, source, sourceLen)
0028 Bytef *dest;
0029 uLongf *destLen;
0030 const Bytef *source;
0031 uLong *sourceLen;
0032 {
0033 z_stream stream;
0034 int err;
0035 const uInt max = (uInt)-1;
0036 uLong len, left;
0037 Byte buf[1];
0038
0039 len = *sourceLen;
0040 if (*destLen) {
0041 left = *destLen;
0042 *destLen = 0;
0043 }
0044 else {
0045 left = 1;
0046 dest = buf;
0047 }
0048
0049 stream.next_in = (z_const Bytef *)source;
0050 stream.avail_in = 0;
0051 stream.zalloc = (alloc_func)0;
0052 stream.zfree = (free_func)0;
0053 stream.opaque = (voidpf)0;
0054
0055 err = inflateInit(&stream);
0056 if (err != Z_OK) return err;
0057
0058 stream.next_out = dest;
0059 stream.avail_out = 0;
0060
0061 do {
0062 if (stream.avail_out == 0) {
0063 stream.avail_out = left > (uLong)max ? max : (uInt)left;
0064 left -= stream.avail_out;
0065 }
0066 if (stream.avail_in == 0) {
0067 stream.avail_in = len > (uLong)max ? max : (uInt)len;
0068 len -= stream.avail_in;
0069 }
0070 err = inflate(&stream, Z_NO_FLUSH);
0071 } while (err == Z_OK);
0072
0073 *sourceLen -= len + stream.avail_in;
0074 if (dest != buf)
0075 *destLen = stream.total_out;
0076 else if (stream.total_out && err == Z_BUF_ERROR)
0077 left = 1;
0078
0079 inflateEnd(&stream);
0080 return err == Z_STREAM_END ? Z_OK :
0081 err == Z_NEED_DICT ? Z_DATA_ERROR :
0082 err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
0083 err;
0084 }
0085
0086 int ZEXPORT uncompress(dest, destLen, source, sourceLen)
0087 Bytef *dest;
0088 uLongf *destLen;
0089 const Bytef *source;
0090 uLong sourceLen;
0091 {
0092 return uncompress2(dest, destLen, source, &sourceLen);
0093 }