14 const char *
const z_errmsg[10] = {
21 "insufficient memory",
23 "incompatible version",
27 const char * ZEXPORT zlibVersion()
32 uLong ZEXPORT zlibCompileFlags()
37 switch (
sizeof(uInt)) {
39 case 4: flags += 1;
break;
40 case 8: flags += 2;
break;
43 switch (
sizeof(uLong)) {
45 case 4: flags += 1 << 2;
break;
46 case 8: flags += 2 << 2;
break;
47 default: flags += 3 << 2;
49 switch (
sizeof(voidpf)) {
51 case 4: flags += 1 << 4;
break;
52 case 8: flags += 2 << 4;
break;
53 default: flags += 3 << 4;
55 switch (
sizeof(z_off_t)) {
57 case 4: flags += 1 << 6;
break;
58 case 8: flags += 2 << 6;
break;
59 default: flags += 3 << 6;
64 #if defined(ASMV) || defined(ASMINF)
73 #ifdef DYNAMIC_CRC_TABLE
82 #ifdef PKZIP_BUG_WORKAROUND
91 # ifdef HAS_vsprintf_void
95 # ifdef HAS_vsnprintf_void
103 # ifdef HAS_sprintf_void
107 # ifdef HAS_snprintf_void
120 int z_verbose = verbose;
125 fprintf(stderr,
"%s\n", m);
133 const char * ZEXPORT zError(err)
139 #if defined(_WIN32_WCE)
149 void zmemcpy(dest, source, len)
154 if (len == 0)
return;
157 }
while (--len != 0);
160 int zmemcmp(s1, s2, len)
167 for (j = 0; j < len; j++) {
168 if (s1[j] != s2[j])
return 2*(s1[j] > s2[j])-1;
173 void zmemzero(dest, len)
177 if (len == 0)
return;
180 }
while (--len != 0);
201 local
int next_ptr = 0;
203 typedef struct ptr_table_s {
208 local ptr_table
table[MAX_PTR];
216 voidpf zcalloc (voidpf opaque,
unsigned items,
unsigned size)
219 ulg bsize = (ulg)items*size;
224 if (bsize < 65520L) {
225 buf = farmalloc(bsize);
226 if (*(ush*)&buf != 0)
return buf;
228 buf = farmalloc(bsize + 16L);
230 if (buf == NULL || next_ptr >= MAX_PTR)
return NULL;
231 table[next_ptr].org_ptr =
buf;
234 *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
236 table[next_ptr++].new_ptr =
buf;
240 void zcfree (voidpf opaque, voidpf ptr)
243 if (*(ush*)&ptr != 0) {
248 for (n = 0; n < next_ptr; n++) {
249 if (ptr != table[n].new_ptr)
continue;
251 farfree(table[n].org_ptr);
252 while (++n < next_ptr) {
253 table[n-1] = table[
n];
259 Assert(0,
"zcfree: ptr not found");
270 #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
271 # define _halloc halloc
272 # define _hfree hfree
275 voidpf zcalloc (voidpf opaque,
unsigned items,
unsigned size)
277 if (opaque) opaque = 0;
278 return _halloc((
long)items, size);
281 void zcfree (voidpf opaque, voidpf ptr)
283 if (opaque) opaque = 0;
295 extern voidp malloc OF((uInt size));
296 extern voidp calloc OF((uInt items, uInt size));
297 extern void free OF((voidpf ptr));
300 voidpf zcalloc (opaque, items, size)
305 if (opaque) items += size -
size;
306 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
307 (voidpf)calloc(items, size);
310 void zcfree (opaque, ptr)