Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
uncompr.c File Reference
#include "zlib.h"

Go to the source code of this file.

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

Definition at line 8 of file uncompr.c.

Function Documentation

◆ uncompress()

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

Definition at line 82 of file uncompr.c.

83 {
84 return uncompress2(dest, destLen, source, &sourceLen);
85}
int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source, uLong *sourceLen)
Definition uncompr.c:27

Referenced by G4ParticleHPManager::GetDataStream(), and G4OpticalSurface::ReadCompressedFile().

◆ uncompress2()

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

Definition at line 27 of file uncompr.c.

28 {
29 z_stream stream;
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}
T max(const T t1, const T t2)
brief Return the largest of the two arguments
uInt avail_in
Definition zlib.h:88
alloc_func zalloc
Definition zlib.h:98
uInt avail_out
Definition zlib.h:92
z_const Bytef * next_in
Definition zlib.h:87
free_func zfree
Definition zlib.h:99
voidpf opaque
Definition zlib.h:100
uLong total_out
Definition zlib.h:93
Bytef * next_out
Definition zlib.h:91
void(* free_func)(voidpf opaque, voidpf address)
Definition zlib.h:82
#define Z_NEED_DICT
Definition zlib.h:179
#define Z_BUF_ERROR
Definition zlib.h:184
voidpf(* alloc_func)(voidpf opaque, uInt items, uInt size)
Definition zlib.h:81
ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush)
Definition inflate.c:590
ZEXTERN int ZEXPORT inflateEnd(z_streamp strm)
Definition inflate.c:1266
#define Z_STREAM_END
Definition zlib.h:178
#define Z_OK
Definition zlib.h:177
#define Z_DATA_ERROR
Definition zlib.h:182
struct z_stream_s z_stream
#define Z_NO_FLUSH
Definition zlib.h:168
#define inflateInit(strm)
Definition zlib.h:1815

Referenced by uncompress().