comparison zlib/zutil.c @ 2690:9ef72ee5c0b0

Update vendored zlib to 1.3.1
author Michael Pavone <pavone@retrodev.com>
date Sun, 15 Jun 2025 15:39:33 -0700
parents 00d788dac91a
children
comparison
equal deleted inserted replaced
2689:bd6e33de0972 2690:9ef72ee5c0b0
22 (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */ 22 (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
23 (z_const char *)"" 23 (z_const char *)""
24 }; 24 };
25 25
26 26
27 const char * ZEXPORT zlibVersion() 27 const char * ZEXPORT zlibVersion(void) {
28 {
29 return ZLIB_VERSION; 28 return ZLIB_VERSION;
30 } 29 }
31 30
32 uLong ZEXPORT zlibCompileFlags() 31 uLong ZEXPORT zlibCompileFlags(void) {
33 {
34 uLong flags; 32 uLong flags;
35 33
36 flags = 0; 34 flags = 0;
37 switch ((int)(sizeof(uInt))) { 35 switch ((int)(sizeof(uInt))) {
38 case 2: break; 36 case 2: break;
59 default: flags += 3 << 6; 57 default: flags += 3 << 6;
60 } 58 }
61 #ifdef ZLIB_DEBUG 59 #ifdef ZLIB_DEBUG
62 flags += 1 << 8; 60 flags += 1 << 8;
63 #endif 61 #endif
62 /*
64 #if defined(ASMV) || defined(ASMINF) 63 #if defined(ASMV) || defined(ASMINF)
65 flags += 1 << 9; 64 flags += 1 << 9;
66 #endif 65 #endif
66 */
67 #ifdef ZLIB_WINAPI 67 #ifdef ZLIB_WINAPI
68 flags += 1 << 10; 68 flags += 1 << 10;
69 #endif 69 #endif
70 #ifdef BUILDFIXED 70 #ifdef BUILDFIXED
71 flags += 1 << 12; 71 flags += 1 << 12;
117 # ifndef verbose 117 # ifndef verbose
118 # define verbose 0 118 # define verbose 0
119 # endif 119 # endif
120 int ZLIB_INTERNAL z_verbose = verbose; 120 int ZLIB_INTERNAL z_verbose = verbose;
121 121
122 void ZLIB_INTERNAL z_error (m) 122 void ZLIB_INTERNAL z_error(char *m) {
123 char *m;
124 {
125 fprintf(stderr, "%s\n", m); 123 fprintf(stderr, "%s\n", m);
126 exit(1); 124 exit(1);
127 } 125 }
128 #endif 126 #endif
129 127
130 /* exported to allow conversion of error code to string for compress() and 128 /* exported to allow conversion of error code to string for compress() and
131 * uncompress() 129 * uncompress()
132 */ 130 */
133 const char * ZEXPORT zError(err) 131 const char * ZEXPORT zError(int err) {
134 int err;
135 {
136 return ERR_MSG(err); 132 return ERR_MSG(err);
137 } 133 }
138 134
139 #if defined(_WIN32_WCE) 135 #if defined(_WIN32_WCE) && _WIN32_WCE < 0x800
140 /* The Microsoft C Run-Time Library for Windows CE doesn't have 136 /* The older Microsoft C Run-Time Library for Windows CE doesn't have
141 * errno. We define it as a global variable to simplify porting. 137 * errno. We define it as a global variable to simplify porting.
142 * Its value is always 0 and should not be used. 138 * Its value is always 0 and should not be used.
143 */ 139 */
144 int errno = 0; 140 int errno = 0;
145 #endif 141 #endif
146 142
147 #ifndef HAVE_MEMCPY 143 #ifndef HAVE_MEMCPY
148 144
149 void ZLIB_INTERNAL zmemcpy(dest, source, len) 145 void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) {
150 Bytef* dest;
151 const Bytef* source;
152 uInt len;
153 {
154 if (len == 0) return; 146 if (len == 0) return;
155 do { 147 do {
156 *dest++ = *source++; /* ??? to be unrolled */ 148 *dest++ = *source++; /* ??? to be unrolled */
157 } while (--len != 0); 149 } while (--len != 0);
158 } 150 }
159 151
160 int ZLIB_INTERNAL zmemcmp(s1, s2, len) 152 int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) {
161 const Bytef* s1;
162 const Bytef* s2;
163 uInt len;
164 {
165 uInt j; 153 uInt j;
166 154
167 for (j = 0; j < len; j++) { 155 for (j = 0; j < len; j++) {
168 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 156 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
169 } 157 }
170 return 0; 158 return 0;
171 } 159 }
172 160
173 void ZLIB_INTERNAL zmemzero(dest, len) 161 void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) {
174 Bytef* dest;
175 uInt len;
176 {
177 if (len == 0) return; 162 if (len == 0) return;
178 do { 163 do {
179 *dest++ = 0; /* ??? to be unrolled */ 164 *dest++ = 0; /* ??? to be unrolled */
180 } while (--len != 0); 165 } while (--len != 0);
181 } 166 }
212 * Since MSDOS is not a preemptive multitasking OS, this table is not 197 * Since MSDOS is not a preemptive multitasking OS, this table is not
213 * protected from concurrent access. This hack doesn't work anyway on 198 * protected from concurrent access. This hack doesn't work anyway on
214 * a protected system like OS/2. Use Microsoft C instead. 199 * a protected system like OS/2. Use Microsoft C instead.
215 */ 200 */
216 201
217 voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) 202 voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
218 {
219 voidpf buf; 203 voidpf buf;
220 ulg bsize = (ulg)items*size; 204 ulg bsize = (ulg)items*size;
221 205
222 (void)opaque; 206 (void)opaque;
223 207
238 *(ush*)&buf = 0; 222 *(ush*)&buf = 0;
239 table[next_ptr++].new_ptr = buf; 223 table[next_ptr++].new_ptr = buf;
240 return buf; 224 return buf;
241 } 225 }
242 226
243 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) 227 void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
244 {
245 int n; 228 int n;
246 229
247 (void)opaque; 230 (void)opaque;
248 231
249 if (*(ush*)&ptr != 0) { /* object < 64K */ 232 if (*(ush*)&ptr != 0) { /* object < 64K */
275 #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 258 #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
276 # define _halloc halloc 259 # define _halloc halloc
277 # define _hfree hfree 260 # define _hfree hfree
278 #endif 261 #endif
279 262
280 voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) 263 voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) {
281 {
282 (void)opaque; 264 (void)opaque;
283 return _halloc((long)items, size); 265 return _halloc((long)items, size);
284 } 266 }
285 267
286 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) 268 void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
287 {
288 (void)opaque; 269 (void)opaque;
289 _hfree(ptr); 270 _hfree(ptr);
290 } 271 }
291 272
292 #endif /* M_I86 */ 273 #endif /* M_I86 */
295 276
296 277
297 #ifndef MY_ZCALLOC /* Any system without a special alloc function */ 278 #ifndef MY_ZCALLOC /* Any system without a special alloc function */
298 279
299 #ifndef STDC 280 #ifndef STDC
300 extern voidp malloc OF((uInt size)); 281 extern voidp malloc(uInt size);
301 extern voidp calloc OF((uInt items, uInt size)); 282 extern voidp calloc(uInt items, uInt size);
302 extern void free OF((voidpf ptr)); 283 extern void free(voidpf ptr);
303 #endif 284 #endif
304 285
305 voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) 286 voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) {
306 voidpf opaque;
307 unsigned items;
308 unsigned size;
309 {
310 (void)opaque; 287 (void)opaque;
311 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : 288 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
312 (voidpf)calloc(items, size); 289 (voidpf)calloc(items, size);
313 } 290 }
314 291
315 void ZLIB_INTERNAL zcfree (opaque, ptr) 292 void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) {
316 voidpf opaque;
317 voidpf ptr;
318 {
319 (void)opaque; 293 (void)opaque;
320 free(ptr); 294 free(ptr);
321 } 295 }
322 296
323 #endif /* MY_ZCALLOC */ 297 #endif /* MY_ZCALLOC */