]>
git.saurik.com Git - apple/security.git/blob - SecurityServer/MacYarrow/zlib/zutil.c
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
19 /* zutil.c -- target dependent utility functions for the compression library
20 * Copyright (C) 1995-1998 Jean-loup Gailly.
21 * For conditions of distribution and use, see copyright notice in zlib.h
24 /* @(#) $Id: zutil.c,v 1.1.1.1 2001/05/18 23:14:03 mb Exp $ */
28 struct internal_state
{int dummy
;}; /* for buggy compilers */
31 extern void exit
OF((int));
34 const char *z_errmsg
[10] = {
35 "need dictionary", /* Z_NEED_DICT 2 */
36 "stream end", /* Z_STREAM_END 1 */
38 "file error", /* Z_ERRNO (-1) */
39 "stream error", /* Z_STREAM_ERROR (-2) */
40 "data error", /* Z_DATA_ERROR (-3) */
41 "insufficient memory", /* Z_MEM_ERROR (-4) */
42 "buffer error", /* Z_BUF_ERROR (-5) */
43 "incompatible version",/* Z_VERSION_ERROR (-6) */
47 const char * ZEXPORT
zlibVersion()
57 int z_verbose
= verbose
;
62 fprintf(stderr
, "%s\n", m
);
67 /* exported to allow conversion of error code to string for compress() and
70 const char * ZEXPORT
zError(err
)
79 void zmemcpy(dest
, source
, len
)
86 *dest
++ = *source
++; /* ??? to be unrolled */
90 int zmemcmp(s1
, s2
, len
)
97 for (j
= 0; j
< len
; j
++) {
98 if (s1
[j
] != s2
[j
]) return 2*(s1
[j
] > s2
[j
])-1;
103 void zmemzero(dest
, len
)
107 if (len
== 0) return;
109 *dest
++ = 0; /* ??? to be unrolled */
110 } while (--len
!= 0);
115 #if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
116 /* Small and medium model in Turbo C are for now limited to near allocation
117 * with reduced MAX_WBITS and MAX_MEM_LEVEL
121 /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
122 * and farmalloc(64K) returns a pointer with an offset of 8, so we
123 * must fix the pointer. Warning: the pointer must be put back to its
124 * original form in order to free it, use zcfree().
130 local
int next_ptr
= 0;
132 typedef struct ptr_table_s
{
137 local ptr_table table
[MAX_PTR
];
138 /* This table is used to remember the original form of pointers
139 * to large buffers (64K). Such pointers are normalized with a zero offset.
140 * Since MSDOS is not a preemptive multitasking OS, this table is not
141 * protected from concurrent access. This hack doesn't work anyway on
142 * a protected system like OS/2. Use Microsoft C instead.
145 voidpf
zcalloc (voidpf opaque
, unsigned items
, unsigned size
)
147 voidpf buf
= opaque
; /* just to make some compilers happy */
148 ulg bsize
= (ulg
)items
*size
;
150 /* If we allocate less than 65520 bytes, we assume that farmalloc
151 * will return a usable pointer which doesn't have to be normalized.
153 if (bsize
< 65520L) {
154 buf
= farmalloc(bsize
);
155 if (*(ush
*)&buf
!= 0) return buf
;
157 buf
= farmalloc(bsize
+ 16L);
159 if (buf
== NULL
|| next_ptr
>= MAX_PTR
) return NULL
;
160 table
[next_ptr
].org_ptr
= buf
;
162 /* Normalize the pointer to seg:0 */
163 *((ush
*)&buf
+1) += ((ush
)((uch
*)buf
-0) + 15) >> 4;
165 table
[next_ptr
++].new_ptr
= buf
;
169 void zcfree (voidpf opaque
, voidpf ptr
)
172 if (*(ush
*)&ptr
!= 0) { /* object < 64K */
176 /* Find the original pointer */
177 for (n
= 0; n
< next_ptr
; n
++) {
178 if (ptr
!= table
[n
].new_ptr
) continue;
180 farfree(table
[n
].org_ptr
);
181 while (++n
< next_ptr
) {
182 table
[n
-1] = table
[n
];
187 ptr
= opaque
; /* just to make some compilers happy */
188 Assert(0, "zcfree: ptr not found");
191 #endif /* __TURBOC__ */
194 #if defined(M_I86) && !defined(__32BIT__)
195 /* Microsoft C in 16-bit mode */
199 #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
200 # define _halloc halloc
201 # define _hfree hfree
204 voidpf
zcalloc (voidpf opaque
, unsigned items
, unsigned size
)
206 if (opaque
) opaque
= 0; /* to make compiler happy */
207 return _halloc((long)items
, size
);
210 void zcfree (voidpf opaque
, voidpf ptr
)
212 if (opaque
) opaque
= 0; /* to make compiler happy */
219 #ifndef MY_ZCALLOC /* Any system without a special alloc function */
222 extern voidp calloc
OF((uInt items
, uInt size
));
223 extern void free
OF((voidpf ptr
));
226 voidpf
zcalloc (opaque
, items
, size
)
231 if (opaque
) items
+= size
- size
; /* make compiler happy */
232 return (voidpf
)calloc(items
, size
);
235 void zcfree (opaque
, ptr
)
240 if (opaque
) return; /* make compiler happy */
243 #endif /* MY_ZCALLOC */