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