TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
uncompr.c
Go to the documentation of this file.
1 /* uncompr.c -- decompress a memory buffer
2  * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler
3  * For conditions of distribution and use, see copyright notice in zlib.h
4  */
5 
6 /* @(#) $Id$ */
7 
8 #define ZLIB_INTERNAL
9 #include "zlib.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 size
14  of the destination buffer, which must be large enough to hold the entire
15  uncompressed data. (The size of the uncompressed data must have been saved
16  previously by the compressor and transmitted to the decompressor by some
17  mechanism outside the scope of this compression library.) Upon exit,
18  *destLen is the size of the decompressed data and *sourceLen is the number
19  of source bytes consumed. Upon return, source + *sourceLen points to the
20  first unused input byte.
21 
22  uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
23  memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
24  Z_DATA_ERROR if the input data was corrupted, including if the input data is
25  an incomplete zlib stream.
26 */
27 int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
28  uLong *sourceLen) {
30  int err;
31  const uInt max = (uInt)-1;
32  uLong len, left;
33  Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
34 
35  len = *sourceLen;
36  if (*destLen) {
37  left = *destLen;
38  *destLen = 0;
39  }
40  else {
41  left = 1;
42  dest = buf;
43  }
44 
45  stream.next_in = (z_const Bytef *)source;
46  stream.avail_in = 0;
47  stream.zalloc = (alloc_func)0;
48  stream.zfree = (free_func)0;
49  stream.opaque = (voidpf)0;
50 
51  err = inflateInit(&stream);
52  if (err != Z_OK) return err;
53 
54  stream.next_out = dest;
55  stream.avail_out = 0;
56 
57  do {
58  if (stream.avail_out == 0) {
59  stream.avail_out = left > (uLong)max ? max : (uInt)left;
60  left -= stream.avail_out;
61  }
62  if (stream.avail_in == 0) {
63  stream.avail_in = len > (uLong)max ? max : (uInt)len;
64  len -= stream.avail_in;
65  }
66  err = inflate(&stream, Z_NO_FLUSH);
67  } while (err == Z_OK);
68 
69  *sourceLen -= len + stream.avail_in;
70  if (dest != buf)
71  *destLen = stream.total_out;
72  else if (stream.total_out && err == Z_BUF_ERROR)
73  left = 1;
74 
75  inflateEnd(&stream);
76  return err == Z_STREAM_END ? Z_OK :
77  err == Z_NEED_DICT ? Z_DATA_ERROR :
78  err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
79  err;
80 }
81 
82 int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
83  uLong sourceLen) {
84  return uncompress2(dest, destLen, source, &sourceLen);
85 }
unsigned char Byte
Definition: zconf.h:393
#define Z_NO_FLUSH
Definition: zlib.h:168
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: uncompr.c:82
uInt avail_in
Definition: zlib.h:88
#define Z_NEED_DICT
Definition: zlib.h:179
voidpf(* alloc_func)(voidpf opaque, uInt items, uInt size)
Definition: zlib.h:81
int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source, uLong *sourceLen)
Definition: uncompr.c:27
#define z_const
Definition: zconf.h:240
Byte FAR Bytef
Definition: zconf.h:402
voidpf opaque
Definition: zlib.h:100
voidpf void * buf
Definition: ioapi.h:136
free_func zfree
Definition: zlib.h:99
constexpr const _Tp & max(const _Tp &a, const _Tp &b)
Definition: ttkcompat.h:33
unsigned long uLong
Definition: zconf.h:396
#define Z_DATA_ERROR
Definition: zlib.h:182
#define Z_STREAM_END
Definition: zlib.h:178
alloc_func zalloc
Definition: zlib.h:98
Bytef * next_out
Definition: zlib.h:91
voidpf stream
Definition: ioapi.h:136
uLong total_out
Definition: zlib.h:93
uLong FAR uLongf
Definition: zconf.h:407
Byte FAR * voidpf
Definition: zconf.h:415
#define Z_BUF_ERROR
Definition: zlib.h:184
#define inflateInit(strm)
Definition: zlib.h:1815
uInt avail_out
Definition: zlib.h:92
z_const Bytef * next_in
Definition: zlib.h:87
#define Z_OK
Definition: zlib.h:177
int ZEXPORT inflate(z_streamp strm, int flush)
Definition: inflate.c:590
void(* free_func)(voidpf opaque, voidpf address)
Definition: zlib.h:82
#define ZEXPORT
Definition: zconf.h:382
int ZEXPORT inflateEnd(z_streamp strm)
Definition: inflate.c:1266
unsigned int uInt
Definition: zconf.h:395