| 1 |
typedef void * (*alloc_func)(void * opaque, unsigned items, unsigned size); |
| 2 |
typedef void (*free_func)(void * opaque, void * address); |
| 3 |
|
| 4 |
typedef struct z_stream_s { |
| 5 |
char *msg; |
| 6 |
alloc_func zalloc; |
| 7 |
free_func zfree; |
| 8 |
void * opaque; |
| 9 |
} z_stream; |
| 10 |
|
| 11 |
void * zcalloc(void * opaque, unsigned items, unsigned size); |
| 12 |
void zcfree(void * opaque, void * ptr); |
| 13 |
|
| 14 |
int deflateInit2_(z_stream *strm, int level, int method, int windowBits, |
| 15 |
int memLevel, int strategy, const char *version, |
| 16 |
int stream_size) { |
| 17 |
int noheader = 0; |
| 18 |
static const char *my_version = "1.1.3"; |
| 19 |
|
| 20 |
if (version == 0 || version[0] != my_version[0] || |
| 21 |
stream_size != sizeof(z_stream)) { |
| 22 |
return (-6); |
| 23 |
} |
| 24 |
if (strm == 0) |
| 25 |
return (-2); |
| 26 |
|
| 27 |
strm->msg = 0; |
| 28 |
if (strm->zalloc == 0) { |
| 29 |
strm->zalloc = zcalloc; |
| 30 |
strm->opaque = (void *)0; |
| 31 |
} |
| 32 |
if (strm->zfree == 0) |
| 33 |
strm->zfree = zcfree; |
| 34 |
|
| 35 |
if (level == (-1)) |
| 36 |
level = 6; |
| 37 |
|
| 38 |
if (windowBits < 0) { |
| 39 |
noheader = 1; |
| 40 |
windowBits = -windowBits; |
| 41 |
} |
| 42 |
if (memLevel < 1 || memLevel > 9 || method != 8 || windowBits < 8 || |
| 43 |
windowBits > 15 || level < 0 || level > 9 || strategy < 0 || |
| 44 |
strategy > 2) { |
| 45 |
return (-2); |
| 46 |
} |
| 47 |
(*((strm)->zalloc))((strm)->opaque, (1), 112); |
| 48 |
return 0; |
| 49 |
} |