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