xref: /xnu-10063.121.3/libkern/zlib/zutil.c (revision 2c2f96dc2b9a4408a43d3150ae9c105355ca3daa)
1*2c2f96dcSApple OSS Distributions /*
2*2c2f96dcSApple OSS Distributions  * Copyright (c) 2008-2016 Apple Inc. All rights reserved.
3*2c2f96dcSApple OSS Distributions  *
4*2c2f96dcSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*2c2f96dcSApple OSS Distributions  *
6*2c2f96dcSApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*2c2f96dcSApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*2c2f96dcSApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*2c2f96dcSApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*2c2f96dcSApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*2c2f96dcSApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*2c2f96dcSApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*2c2f96dcSApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*2c2f96dcSApple OSS Distributions  *
15*2c2f96dcSApple OSS Distributions  * Please obtain a copy of the License at
16*2c2f96dcSApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*2c2f96dcSApple OSS Distributions  *
18*2c2f96dcSApple OSS Distributions  * The Original Code and all software distributed under the License are
19*2c2f96dcSApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*2c2f96dcSApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*2c2f96dcSApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*2c2f96dcSApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*2c2f96dcSApple OSS Distributions  * Please see the License for the specific language governing rights and
24*2c2f96dcSApple OSS Distributions  * limitations under the License.
25*2c2f96dcSApple OSS Distributions  *
26*2c2f96dcSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*2c2f96dcSApple OSS Distributions  */
28*2c2f96dcSApple OSS Distributions /* zutil.c -- target dependent utility functions for the compression library
29*2c2f96dcSApple OSS Distributions  * Copyright (C) 1995-2005 Jean-loup Gailly.
30*2c2f96dcSApple OSS Distributions  * For conditions of distribution and use, see copyright notice in zlib.h
31*2c2f96dcSApple OSS Distributions  */
32*2c2f96dcSApple OSS Distributions 
33*2c2f96dcSApple OSS Distributions /* @(#) $Id$ */
34*2c2f96dcSApple OSS Distributions 
35*2c2f96dcSApple OSS Distributions #include "zutil.h"
36*2c2f96dcSApple OSS Distributions 
37*2c2f96dcSApple OSS Distributions #ifndef NO_DUMMY_DECL
38*2c2f96dcSApple OSS Distributions struct internal_state      {int dummy;}; /* for buggy compilers */
39*2c2f96dcSApple OSS Distributions #endif
40*2c2f96dcSApple OSS Distributions 
41*2c2f96dcSApple OSS Distributions const char * const z_errmsg[10] = {
42*2c2f96dcSApple OSS Distributions "need dictionary",     /* Z_NEED_DICT       2  */
43*2c2f96dcSApple OSS Distributions "stream end",          /* Z_STREAM_END      1  */
44*2c2f96dcSApple OSS Distributions "",                    /* Z_OK              0  */
45*2c2f96dcSApple OSS Distributions "file error",          /* Z_ERRNO         (-1) */
46*2c2f96dcSApple OSS Distributions "stream error",        /* Z_STREAM_ERROR  (-2) */
47*2c2f96dcSApple OSS Distributions "data error",          /* Z_DATA_ERROR    (-3) */
48*2c2f96dcSApple OSS Distributions "insufficient memory", /* Z_MEM_ERROR     (-4) */
49*2c2f96dcSApple OSS Distributions "buffer error",        /* Z_BUF_ERROR     (-5) */
50*2c2f96dcSApple OSS Distributions "incompatible version",/* Z_VERSION_ERROR (-6) */
51*2c2f96dcSApple OSS Distributions ""};
52*2c2f96dcSApple OSS Distributions 
53*2c2f96dcSApple OSS Distributions 
zlibVersion()54*2c2f96dcSApple OSS Distributions const char * ZEXPORT zlibVersion()
55*2c2f96dcSApple OSS Distributions {
56*2c2f96dcSApple OSS Distributions     return ZLIB_VERSION;
57*2c2f96dcSApple OSS Distributions }
58*2c2f96dcSApple OSS Distributions 
zlibCompileFlags()59*2c2f96dcSApple OSS Distributions uLong ZEXPORT zlibCompileFlags()
60*2c2f96dcSApple OSS Distributions {
61*2c2f96dcSApple OSS Distributions     uLong flags;
62*2c2f96dcSApple OSS Distributions 
63*2c2f96dcSApple OSS Distributions     flags = 0;
64*2c2f96dcSApple OSS Distributions     switch (sizeof(uInt)) {
65*2c2f96dcSApple OSS Distributions     case 2:     break;
66*2c2f96dcSApple OSS Distributions     case 4:     flags += 1;     break;
67*2c2f96dcSApple OSS Distributions     case 8:     flags += 2;     break;
68*2c2f96dcSApple OSS Distributions     default:    flags += 3;
69*2c2f96dcSApple OSS Distributions     }
70*2c2f96dcSApple OSS Distributions     switch (sizeof(uLong)) {
71*2c2f96dcSApple OSS Distributions     case 2:     break;
72*2c2f96dcSApple OSS Distributions     case 4:     flags += 1 << 2;        break;
73*2c2f96dcSApple OSS Distributions     case 8:     flags += 2 << 2;        break;
74*2c2f96dcSApple OSS Distributions     default:    flags += 3 << 2;
75*2c2f96dcSApple OSS Distributions     }
76*2c2f96dcSApple OSS Distributions     switch (sizeof(voidpf)) {
77*2c2f96dcSApple OSS Distributions     case 2:     break;
78*2c2f96dcSApple OSS Distributions     case 4:     flags += 1 << 4;        break;
79*2c2f96dcSApple OSS Distributions     case 8:     flags += 2 << 4;        break;
80*2c2f96dcSApple OSS Distributions     default:    flags += 3 << 4;
81*2c2f96dcSApple OSS Distributions     }
82*2c2f96dcSApple OSS Distributions     switch (sizeof(z_off_t)) {
83*2c2f96dcSApple OSS Distributions     case 2:     break;
84*2c2f96dcSApple OSS Distributions     case 4:     flags += 1 << 6;        break;
85*2c2f96dcSApple OSS Distributions     case 8:     flags += 2 << 6;        break;
86*2c2f96dcSApple OSS Distributions     default:    flags += 3 << 6;
87*2c2f96dcSApple OSS Distributions     }
88*2c2f96dcSApple OSS Distributions #ifdef DEBUG
89*2c2f96dcSApple OSS Distributions     flags += 1 << 8;
90*2c2f96dcSApple OSS Distributions #endif
91*2c2f96dcSApple OSS Distributions #if defined(ASMV) || defined(ASMINF)
92*2c2f96dcSApple OSS Distributions     flags += 1 << 9;
93*2c2f96dcSApple OSS Distributions #endif
94*2c2f96dcSApple OSS Distributions #ifdef ZLIB_WINAPI
95*2c2f96dcSApple OSS Distributions     flags += 1 << 10;
96*2c2f96dcSApple OSS Distributions #endif
97*2c2f96dcSApple OSS Distributions #ifdef BUILDFIXED
98*2c2f96dcSApple OSS Distributions     flags += 1 << 12;
99*2c2f96dcSApple OSS Distributions #endif
100*2c2f96dcSApple OSS Distributions #ifdef DYNAMIC_CRC_TABLE
101*2c2f96dcSApple OSS Distributions     flags += 1 << 13;
102*2c2f96dcSApple OSS Distributions #endif
103*2c2f96dcSApple OSS Distributions #ifdef NO_GZCOMPRESS
104*2c2f96dcSApple OSS Distributions     flags += 1L << 16;
105*2c2f96dcSApple OSS Distributions #endif
106*2c2f96dcSApple OSS Distributions #ifdef NO_GZIP
107*2c2f96dcSApple OSS Distributions     flags += 1L << 17;
108*2c2f96dcSApple OSS Distributions #endif
109*2c2f96dcSApple OSS Distributions #ifdef PKZIP_BUG_WORKAROUND
110*2c2f96dcSApple OSS Distributions     flags += 1L << 20;
111*2c2f96dcSApple OSS Distributions #endif
112*2c2f96dcSApple OSS Distributions #ifdef FASTEST
113*2c2f96dcSApple OSS Distributions     flags += 1L << 21;
114*2c2f96dcSApple OSS Distributions #endif
115*2c2f96dcSApple OSS Distributions #ifdef STDC
116*2c2f96dcSApple OSS Distributions #  ifdef NO_vsnprintf
117*2c2f96dcSApple OSS Distributions         flags += 1L << 25;
118*2c2f96dcSApple OSS Distributions #    ifdef HAS_vsprintf_void
119*2c2f96dcSApple OSS Distributions         flags += 1L << 26;
120*2c2f96dcSApple OSS Distributions #    endif
121*2c2f96dcSApple OSS Distributions #  else
122*2c2f96dcSApple OSS Distributions #    ifdef HAS_vsnprintf_void
123*2c2f96dcSApple OSS Distributions         flags += 1L << 26;
124*2c2f96dcSApple OSS Distributions #    endif
125*2c2f96dcSApple OSS Distributions #  endif
126*2c2f96dcSApple OSS Distributions #else
127*2c2f96dcSApple OSS Distributions         flags += 1L << 24;
128*2c2f96dcSApple OSS Distributions #  ifdef NO_snprintf
129*2c2f96dcSApple OSS Distributions         flags += 1L << 25;
130*2c2f96dcSApple OSS Distributions #    ifdef HAS_sprintf_void
131*2c2f96dcSApple OSS Distributions         flags += 1L << 26;
132*2c2f96dcSApple OSS Distributions #    endif
133*2c2f96dcSApple OSS Distributions #  else
134*2c2f96dcSApple OSS Distributions #    ifdef HAS_snprintf_void
135*2c2f96dcSApple OSS Distributions         flags += 1L << 26;
136*2c2f96dcSApple OSS Distributions #    endif
137*2c2f96dcSApple OSS Distributions #  endif
138*2c2f96dcSApple OSS Distributions #endif
139*2c2f96dcSApple OSS Distributions     return flags;
140*2c2f96dcSApple OSS Distributions }
141*2c2f96dcSApple OSS Distributions 
142*2c2f96dcSApple OSS Distributions #ifdef DEBUG
143*2c2f96dcSApple OSS Distributions 
144*2c2f96dcSApple OSS Distributions #  ifndef verbose
145*2c2f96dcSApple OSS Distributions #    define verbose 0
146*2c2f96dcSApple OSS Distributions #  endif
147*2c2f96dcSApple OSS Distributions int z_verbose = verbose;
148*2c2f96dcSApple OSS Distributions 
149*2c2f96dcSApple OSS Distributions void
z_error(char * m)150*2c2f96dcSApple OSS Distributions z_error(char *m)
151*2c2f96dcSApple OSS Distributions {
152*2c2f96dcSApple OSS Distributions     fprintf(stderr, "%s\n", m);
153*2c2f96dcSApple OSS Distributions     exit(1);
154*2c2f96dcSApple OSS Distributions }
155*2c2f96dcSApple OSS Distributions #endif
156*2c2f96dcSApple OSS Distributions 
157*2c2f96dcSApple OSS Distributions /* exported to allow conversion of error code to string for compress() and
158*2c2f96dcSApple OSS Distributions  * uncompress()
159*2c2f96dcSApple OSS Distributions  */
160*2c2f96dcSApple OSS Distributions const char * ZEXPORT
zError(int err)161*2c2f96dcSApple OSS Distributions zError(int err)
162*2c2f96dcSApple OSS Distributions {
163*2c2f96dcSApple OSS Distributions     return ERR_MSG(err);
164*2c2f96dcSApple OSS Distributions }
165*2c2f96dcSApple OSS Distributions 
166*2c2f96dcSApple OSS Distributions #if defined(_WIN32_WCE)
167*2c2f96dcSApple OSS Distributions     /* The Microsoft C Run-Time Library for Windows CE doesn't have
168*2c2f96dcSApple OSS Distributions      * errno.  We define it as a global variable to simplify porting.
169*2c2f96dcSApple OSS Distributions      * Its value is always 0 and should not be used.
170*2c2f96dcSApple OSS Distributions      */
171*2c2f96dcSApple OSS Distributions     int errno = 0;
172*2c2f96dcSApple OSS Distributions #endif
173*2c2f96dcSApple OSS Distributions 
174*2c2f96dcSApple OSS Distributions #ifndef HAVE_MEMCPY
175*2c2f96dcSApple OSS Distributions 
176*2c2f96dcSApple OSS Distributions void
zmemcpy(Bytef * dest,const Bytef * source,uInt len)177*2c2f96dcSApple OSS Distributions zmemcpy(Bytef* dest, const Bytef* source, uInt  len)
178*2c2f96dcSApple OSS Distributions {
179*2c2f96dcSApple OSS Distributions     if (len == 0) return;
180*2c2f96dcSApple OSS Distributions     do {
181*2c2f96dcSApple OSS Distributions         *dest++ = *source++; /* ??? to be unrolled */
182*2c2f96dcSApple OSS Distributions     } while (--len != 0);
183*2c2f96dcSApple OSS Distributions }
184*2c2f96dcSApple OSS Distributions 
185*2c2f96dcSApple OSS Distributions int
zmemcmp(const Bytef * s1,const Bytef * s2,uInt len)186*2c2f96dcSApple OSS Distributions zmemcmp(const Bytef* s1, const Bytef* s2, uInt  len)
187*2c2f96dcSApple OSS Distributions {
188*2c2f96dcSApple OSS Distributions     uInt j;
189*2c2f96dcSApple OSS Distributions 
190*2c2f96dcSApple OSS Distributions     for (j = 0; j < len; j++) {
191*2c2f96dcSApple OSS Distributions         if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
192*2c2f96dcSApple OSS Distributions     }
193*2c2f96dcSApple OSS Distributions     return 0;
194*2c2f96dcSApple OSS Distributions }
195*2c2f96dcSApple OSS Distributions 
196*2c2f96dcSApple OSS Distributions void
zmemzero(Bytef * dest,uInt len)197*2c2f96dcSApple OSS Distributions zmemzero(Bytef* dest, uInt  len)
198*2c2f96dcSApple OSS Distributions {
199*2c2f96dcSApple OSS Distributions     if (len == 0) return;
200*2c2f96dcSApple OSS Distributions     do {
201*2c2f96dcSApple OSS Distributions         *dest++ = 0;  /* ??? to be unrolled */
202*2c2f96dcSApple OSS Distributions     } while (--len != 0);
203*2c2f96dcSApple OSS Distributions }
204*2c2f96dcSApple OSS Distributions #endif
205*2c2f96dcSApple OSS Distributions 
206*2c2f96dcSApple OSS Distributions #ifndef NO_ZCFUNCS
207*2c2f96dcSApple OSS Distributions 
208*2c2f96dcSApple OSS Distributions #ifdef SYS16BIT
209*2c2f96dcSApple OSS Distributions 
210*2c2f96dcSApple OSS Distributions #ifdef __TURBOC__
211*2c2f96dcSApple OSS Distributions /* Turbo C in 16-bit mode */
212*2c2f96dcSApple OSS Distributions 
213*2c2f96dcSApple OSS Distributions #  define MY_ZCALLOC
214*2c2f96dcSApple OSS Distributions 
215*2c2f96dcSApple OSS Distributions /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
216*2c2f96dcSApple OSS Distributions  * and farmalloc(64K) returns a pointer with an offset of 8, so we
217*2c2f96dcSApple OSS Distributions  * must fix the pointer. Warning: the pointer must be put back to its
218*2c2f96dcSApple OSS Distributions  * original form in order to free it, use zcfree().
219*2c2f96dcSApple OSS Distributions  */
220*2c2f96dcSApple OSS Distributions 
221*2c2f96dcSApple OSS Distributions #define MAX_PTR 10
222*2c2f96dcSApple OSS Distributions /* 10*64K = 640K */
223*2c2f96dcSApple OSS Distributions 
224*2c2f96dcSApple OSS Distributions local int next_ptr = 0;
225*2c2f96dcSApple OSS Distributions 
226*2c2f96dcSApple OSS Distributions typedef struct ptr_table_s {
227*2c2f96dcSApple OSS Distributions     voidpf org_ptr;
228*2c2f96dcSApple OSS Distributions     voidpf new_ptr;
229*2c2f96dcSApple OSS Distributions } ptr_table;
230*2c2f96dcSApple OSS Distributions 
231*2c2f96dcSApple OSS Distributions local ptr_table table[MAX_PTR];
232*2c2f96dcSApple OSS Distributions /* This table is used to remember the original form of pointers
233*2c2f96dcSApple OSS Distributions  * to large buffers (64K). Such pointers are normalized with a zero offset.
234*2c2f96dcSApple OSS Distributions  * Since MSDOS is not a preemptive multitasking OS, this table is not
235*2c2f96dcSApple OSS Distributions  * protected from concurrent access. This hack doesn't work anyway on
236*2c2f96dcSApple OSS Distributions  * a protected system like OS/2. Use Microsoft C instead.
237*2c2f96dcSApple OSS Distributions  */
238*2c2f96dcSApple OSS Distributions 
239*2c2f96dcSApple OSS Distributions voidpf
zcalloc(voidpf opaque,unsigned items,unsigned size)240*2c2f96dcSApple OSS Distributions zcalloc(voidpf opaque, unsigned items, unsigned size)
241*2c2f96dcSApple OSS Distributions {
242*2c2f96dcSApple OSS Distributions     voidpf buf = opaque; /* just to make some compilers happy */
243*2c2f96dcSApple OSS Distributions     ulg bsize = (ulg)items*size;
244*2c2f96dcSApple OSS Distributions 
245*2c2f96dcSApple OSS Distributions     /* If we allocate less than 65520 bytes, we assume that farmalloc
246*2c2f96dcSApple OSS Distributions      * will return a usable pointer which doesn't have to be normalized.
247*2c2f96dcSApple OSS Distributions      */
248*2c2f96dcSApple OSS Distributions     if (bsize < 65520L) {
249*2c2f96dcSApple OSS Distributions         buf = farmalloc(bsize);
250*2c2f96dcSApple OSS Distributions         if (*(ush*)&buf != 0) return buf;
251*2c2f96dcSApple OSS Distributions     } else {
252*2c2f96dcSApple OSS Distributions         buf = farmalloc(bsize + 16L);
253*2c2f96dcSApple OSS Distributions     }
254*2c2f96dcSApple OSS Distributions     if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
255*2c2f96dcSApple OSS Distributions     table[next_ptr].org_ptr = buf;
256*2c2f96dcSApple OSS Distributions 
257*2c2f96dcSApple OSS Distributions     /* Normalize the pointer to seg:0 */
258*2c2f96dcSApple OSS Distributions     *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
259*2c2f96dcSApple OSS Distributions     *(ush*)&buf = 0;
260*2c2f96dcSApple OSS Distributions     table[next_ptr++].new_ptr = buf;
261*2c2f96dcSApple OSS Distributions     return buf;
262*2c2f96dcSApple OSS Distributions }
263*2c2f96dcSApple OSS Distributions 
264*2c2f96dcSApple OSS Distributions void
zcfree(voidpf opaque,voidpf ptr)265*2c2f96dcSApple OSS Distributions zcfree(voidpf opaque, voidpf ptr)
266*2c2f96dcSApple OSS Distributions {
267*2c2f96dcSApple OSS Distributions     int n;
268*2c2f96dcSApple OSS Distributions     if (*(ush*)&ptr != 0) { /* object < 64K */
269*2c2f96dcSApple OSS Distributions         farfree(ptr);
270*2c2f96dcSApple OSS Distributions         return;
271*2c2f96dcSApple OSS Distributions     }
272*2c2f96dcSApple OSS Distributions     /* Find the original pointer */
273*2c2f96dcSApple OSS Distributions     for (n = 0; n < next_ptr; n++) {
274*2c2f96dcSApple OSS Distributions         if (ptr != table[n].new_ptr) continue;
275*2c2f96dcSApple OSS Distributions 
276*2c2f96dcSApple OSS Distributions         farfree(table[n].org_ptr);
277*2c2f96dcSApple OSS Distributions         while (++n < next_ptr) {
278*2c2f96dcSApple OSS Distributions             table[n-1] = table[n];
279*2c2f96dcSApple OSS Distributions         }
280*2c2f96dcSApple OSS Distributions         next_ptr--;
281*2c2f96dcSApple OSS Distributions         return;
282*2c2f96dcSApple OSS Distributions     }
283*2c2f96dcSApple OSS Distributions     ptr = opaque; /* just to make some compilers happy */
284*2c2f96dcSApple OSS Distributions     Assert(0, "zcfree: ptr not found");
285*2c2f96dcSApple OSS Distributions }
286*2c2f96dcSApple OSS Distributions 
287*2c2f96dcSApple OSS Distributions #endif /* __TURBOC__ */
288*2c2f96dcSApple OSS Distributions 
289*2c2f96dcSApple OSS Distributions 
290*2c2f96dcSApple OSS Distributions #ifdef M_I86
291*2c2f96dcSApple OSS Distributions /* Microsoft C in 16-bit mode */
292*2c2f96dcSApple OSS Distributions 
293*2c2f96dcSApple OSS Distributions #  define MY_ZCALLOC
294*2c2f96dcSApple OSS Distributions 
295*2c2f96dcSApple OSS Distributions #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
296*2c2f96dcSApple OSS Distributions #  define _halloc  halloc
297*2c2f96dcSApple OSS Distributions #  define _hfree   hfree
298*2c2f96dcSApple OSS Distributions #endif
299*2c2f96dcSApple OSS Distributions 
300*2c2f96dcSApple OSS Distributions voidpf
zcalloc(voidpf opaque,unsigned items,unsigned size)301*2c2f96dcSApple OSS Distributions zcalloc(voidpf opaque, unsigned items, unsigned size)
302*2c2f96dcSApple OSS Distributions {
303*2c2f96dcSApple OSS Distributions     if (opaque) opaque = 0; /* to make compiler happy */
304*2c2f96dcSApple OSS Distributions     return _halloc((long)items, size);
305*2c2f96dcSApple OSS Distributions }
306*2c2f96dcSApple OSS Distributions 
307*2c2f96dcSApple OSS Distributions void
zcfree(voidpf opaque,voidpf ptr)308*2c2f96dcSApple OSS Distributions zcfree(voidpf opaque, voidpf ptr)
309*2c2f96dcSApple OSS Distributions {
310*2c2f96dcSApple OSS Distributions     if (opaque) opaque = 0; /* to make compiler happy */
311*2c2f96dcSApple OSS Distributions     _hfree(ptr);
312*2c2f96dcSApple OSS Distributions }
313*2c2f96dcSApple OSS Distributions 
314*2c2f96dcSApple OSS Distributions #endif /* M_I86 */
315*2c2f96dcSApple OSS Distributions 
316*2c2f96dcSApple OSS Distributions #endif /* SYS16BIT */
317*2c2f96dcSApple OSS Distributions 
318*2c2f96dcSApple OSS Distributions 
319*2c2f96dcSApple OSS Distributions #ifndef MY_ZCALLOC /* Any system without a special alloc function */
320*2c2f96dcSApple OSS Distributions 
321*2c2f96dcSApple OSS Distributions #ifndef STDC
322*2c2f96dcSApple OSS Distributions extern voidp  malloc OF((uInt size));
323*2c2f96dcSApple OSS Distributions extern voidp  calloc OF((uInt items, uInt size));
324*2c2f96dcSApple OSS Distributions extern void   free   OF((voidpf ptr));
325*2c2f96dcSApple OSS Distributions #endif
326*2c2f96dcSApple OSS Distributions 
327*2c2f96dcSApple OSS Distributions voidpf
zcalloc(voidpf opaque,unsigned items,unsigned size)328*2c2f96dcSApple OSS Distributions zcalloc(voidpf opaque, unsigned items, unsigned size)
329*2c2f96dcSApple OSS Distributions {
330*2c2f96dcSApple OSS Distributions     if (opaque) items += size - size; /* make compiler happy */
331*2c2f96dcSApple OSS Distributions     if (sizeof(uInt) > 2) {
332*2c2f96dcSApple OSS Distributions         /*
333*2c2f96dcSApple OSS Distributions             to prevent use of uninitialized memory, malloc and bzero
334*2c2f96dcSApple OSS Distributions         */
335*2c2f96dcSApple OSS Distributions         voidpf  p = malloc(items * size);
336*2c2f96dcSApple OSS Distributions         bzero(p, items * size);
337*2c2f96dcSApple OSS Distributions         return p;
338*2c2f96dcSApple OSS Distributions     } else
339*2c2f96dcSApple OSS Distributions         return (voidpf)calloc(items, size);
340*2c2f96dcSApple OSS Distributions }
341*2c2f96dcSApple OSS Distributions 
342*2c2f96dcSApple OSS Distributions void
zcfree(voidpf opaque,voidpf ptr)343*2c2f96dcSApple OSS Distributions zcfree(voidpf opaque, voidpf ptr)
344*2c2f96dcSApple OSS Distributions {
345*2c2f96dcSApple OSS Distributions     free(ptr);
346*2c2f96dcSApple OSS Distributions     if (opaque) return; /* make compiler happy */
347*2c2f96dcSApple OSS Distributions }
348*2c2f96dcSApple OSS Distributions 
349*2c2f96dcSApple OSS Distributions #endif /* MY_ZCALLOC */
350*2c2f96dcSApple OSS Distributions 
351*2c2f96dcSApple OSS Distributions #endif /* NO_CZFUNCS */
352