Prusa MINI Firmware overview
uncompr.c File Reference
#include "zlib.h"

Macros

#define ZLIB_INTERNAL
 

Functions

int ZEXPORT uncompress2 (Bytef *dest, uLongf *destLen, const Bytef *source, uLong *sourceLen)
 
int ZEXPORT uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
 

Macro Definition Documentation

◆ ZLIB_INTERNAL

#define ZLIB_INTERNAL

Function Documentation

◆ uncompress2()

int ZEXPORT uncompress2 ( Bytef dest,
uLongf destLen,
const Bytef source,
uLong sourceLen 
)
32 {
33  z_stream stream;
34  int err;
35  const uInt max = (uInt)-1;
36  uLong len, left;
37  Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
38 
39  len = *sourceLen;
40  if (*destLen) {
41  left = *destLen;
42  *destLen = 0;
43  }
44  else {
45  left = 1;
46  dest = buf;
47  }
48 
49  stream.next_in = (z_const Bytef *)source;
50  stream.avail_in = 0;
51  stream.zalloc = (alloc_func)0;
52  stream.zfree = (free_func)0;
53  stream.opaque = (voidpf)0;
54 
55  err = inflateInit(&stream);
56  if (err != Z_OK) return err;
57 
58  stream.next_out = dest;
59  stream.avail_out = 0;
60 
61  do {
62  if (stream.avail_out == 0) {
63  stream.avail_out = left > (uLong)max ? max : (uInt)left;
64  left -= stream.avail_out;
65  }
66  if (stream.avail_in == 0) {
67  stream.avail_in = len > (uLong)max ? max : (uInt)len;
68  len -= stream.avail_in;
69  }
70  err = inflate(&stream, Z_NO_FLUSH);
71  } while (err == Z_OK);
72 
73  *sourceLen -= len + stream.avail_in;
74  if (dest != buf)
75  *destLen = stream.total_out;
76  else if (stream.total_out && err == Z_BUF_ERROR)
77  left = 1;
78 
79  inflateEnd(&stream);
80  return err == Z_STREAM_END ? Z_OK :
81  err == Z_NEED_DICT ? Z_DATA_ERROR :
82  err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
83  err;
84 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uncompress()

int ZEXPORT uncompress ( Bytef dest,
uLongf destLen,
const Bytef source,
uLong  sourceLen 
)
91 {
92  return uncompress2(dest, destLen, source, &sourceLen);
93 }
Here is the call graph for this function:
Bytef
Byte FAR Bytef
Definition: zconf.h:400
Z_BUF_ERROR
#define Z_BUF_ERROR
Definition: zlib.h:184
uLong
unsigned long uLong
Definition: zconf.h:394
uncompress2
int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source, uLong *sourceLen)
Definition: uncompr.c:27
z_stream_s::zfree
free_func zfree
Definition: zlib.h:99
Z_DATA_ERROR
#define Z_DATA_ERROR
Definition: zlib.h:182
z_stream_s::avail_in
uInt avail_in
Definition: zlib.h:88
Z_NEED_DICT
#define Z_NEED_DICT
Definition: zlib.h:179
max
#define max(a, b)
Definition: wiring_constants.h:40
inflateInit
#define inflateInit(strm)
Definition: zlib.h:1795
voidpf
Byte FAR * voidpf
Definition: zconf.h:413
z_stream_s::avail_out
uInt avail_out
Definition: zlib.h:92
Byte
unsigned char Byte
Definition: zconf.h:391
z_const
#define z_const
Definition: zconf.h:237
Z_NO_FLUSH
#define Z_NO_FLUSH
Definition: zlib.h:168
Z_OK
#define Z_OK
Definition: zlib.h:177
z_stream_s::zalloc
alloc_func zalloc
Definition: zlib.h:98
Z_STREAM_END
#define Z_STREAM_END
Definition: zlib.h:178
z_stream_s
Definition: zlib.h:86
z_stream_s::next_in
z_const Bytef * next_in
Definition: zlib.h:87
z_stream_s::next_out
Bytef * next_out
Definition: zlib.h:91
uInt
unsigned int uInt
Definition: zconf.h:393
inflateEnd
int ZEXPORT inflateEnd(z_streamp strm)
Definition: inflate.c:1277
z_stream_s::opaque
voidpf opaque
Definition: zlib.h:100
inflate
int ZEXPORT inflate(z_streamp strm, int flush)
Definition: inflate.c:622
z_stream_s::total_out
uLong total_out
Definition: zlib.h:93