OLD | NEW |
1 /* zutil.c -- target dependent utility functions for the compression library | 1 /* zutil.c -- target dependent utility functions for the compression library |
2 * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly. | 2 * Copyright (C) 1995-2017 Jean-loup Gailly |
3 * For conditions of distribution and use, see copyright notice in zlib.h | 3 * For conditions of distribution and use, see copyright notice in zlib.h |
4 */ | 4 */ |
5 | 5 |
6 /* @(#) $Id$ */ | 6 /* @(#) $Id$ */ |
7 | 7 |
8 #include "zutil.h" | 8 #include "zutil.h" |
9 #ifndef Z_SOLO | 9 #ifndef Z_SOLO |
10 # include "gzguts.h" | 10 # include "gzguts.h" |
11 #endif | 11 #endif |
12 | 12 |
13 #ifndef NO_DUMMY_DECL | |
14 struct internal_state {int dummy;}; /* for buggy compilers */ | |
15 #endif | |
16 | |
17 z_const char * const z_errmsg[10] = { | 13 z_const char * const z_errmsg[10] = { |
18 "need dictionary", /* Z_NEED_DICT 2 */ | 14 (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */ |
19 "stream end", /* Z_STREAM_END 1 */ | 15 (z_const char *)"stream end", /* Z_STREAM_END 1 */ |
20 "", /* Z_OK 0 */ | 16 (z_const char *)"", /* Z_OK 0 */ |
21 "file error", /* Z_ERRNO (-1) */ | 17 (z_const char *)"file error", /* Z_ERRNO (-1) */ |
22 "stream error", /* Z_STREAM_ERROR (-2) */ | 18 (z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */ |
23 "data error", /* Z_DATA_ERROR (-3) */ | 19 (z_const char *)"data error", /* Z_DATA_ERROR (-3) */ |
24 "insufficient memory", /* Z_MEM_ERROR (-4) */ | 20 (z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */ |
25 "buffer error", /* Z_BUF_ERROR (-5) */ | 21 (z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */ |
26 "incompatible version",/* Z_VERSION_ERROR (-6) */ | 22 (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */ |
27 ""}; | 23 (z_const char *)"" |
| 24 }; |
28 | 25 |
29 | 26 |
30 const char * ZEXPORT zlibVersion() | 27 const char * ZEXPORT zlibVersion() |
31 { | 28 { |
32 return ZLIB_VERSION; | 29 return ZLIB_VERSION; |
33 } | 30 } |
34 | 31 |
35 uLong ZEXPORT zlibCompileFlags() | 32 uLong ZEXPORT zlibCompileFlags() |
36 { | 33 { |
37 uLong flags; | 34 uLong flags; |
(...skipping 16 matching lines...) Expand all Loading... |
54 case 4: flags += 1 << 4; break; | 51 case 4: flags += 1 << 4; break; |
55 case 8: flags += 2 << 4; break; | 52 case 8: flags += 2 << 4; break; |
56 default: flags += 3 << 4; | 53 default: flags += 3 << 4; |
57 } | 54 } |
58 switch ((int)(sizeof(z_off_t))) { | 55 switch ((int)(sizeof(z_off_t))) { |
59 case 2: break; | 56 case 2: break; |
60 case 4: flags += 1 << 6; break; | 57 case 4: flags += 1 << 6; break; |
61 case 8: flags += 2 << 6; break; | 58 case 8: flags += 2 << 6; break; |
62 default: flags += 3 << 6; | 59 default: flags += 3 << 6; |
63 } | 60 } |
64 #ifdef DEBUG | 61 #ifdef ZLIB_DEBUG |
65 flags += 1 << 8; | 62 flags += 1 << 8; |
66 #endif | 63 #endif |
67 #if defined(ASMV) || defined(ASMINF) | 64 #if defined(ASMV) || defined(ASMINF) |
68 flags += 1 << 9; | 65 flags += 1 << 9; |
69 #endif | 66 #endif |
70 #ifdef ZLIB_WINAPI | 67 #ifdef ZLIB_WINAPI |
71 flags += 1 << 10; | 68 flags += 1 << 10; |
72 #endif | 69 #endif |
73 #ifdef BUILDFIXED | 70 #ifdef BUILDFIXED |
74 flags += 1 << 12; | 71 flags += 1 << 12; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 # endif | 105 # endif |
109 # else | 106 # else |
110 # ifdef HAS_snprintf_void | 107 # ifdef HAS_snprintf_void |
111 flags += 1L << 26; | 108 flags += 1L << 26; |
112 # endif | 109 # endif |
113 # endif | 110 # endif |
114 #endif | 111 #endif |
115 return flags; | 112 return flags; |
116 } | 113 } |
117 | 114 |
118 #ifdef DEBUG | 115 #ifdef ZLIB_DEBUG |
119 | 116 #include <stdlib.h> |
120 # ifndef verbose | 117 # ifndef verbose |
121 # define verbose 0 | 118 # define verbose 0 |
122 # endif | 119 # endif |
123 int ZLIB_INTERNAL z_verbose = verbose; | 120 int ZLIB_INTERNAL z_verbose = verbose; |
124 | 121 |
125 void ZLIB_INTERNAL z_error (m) | 122 void ZLIB_INTERNAL z_error (m) |
126 char *m; | 123 char *m; |
127 { | 124 { |
128 fprintf(stderr, "%s\n", m); | 125 fprintf(stderr, "%s\n", m); |
129 exit(1); | 126 exit(1); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 local ptr_table table[MAX_PTR]; | 209 local ptr_table table[MAX_PTR]; |
213 /* This table is used to remember the original form of pointers | 210 /* This table is used to remember the original form of pointers |
214 * to large buffers (64K). Such pointers are normalized with a zero offset. | 211 * to large buffers (64K). Such pointers are normalized with a zero offset. |
215 * Since MSDOS is not a preemptive multitasking OS, this table is not | 212 * Since MSDOS is not a preemptive multitasking OS, this table is not |
216 * protected from concurrent access. This hack doesn't work anyway on | 213 * protected from concurrent access. This hack doesn't work anyway on |
217 * a protected system like OS/2. Use Microsoft C instead. | 214 * a protected system like OS/2. Use Microsoft C instead. |
218 */ | 215 */ |
219 | 216 |
220 voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) | 217 voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) |
221 { | 218 { |
222 voidpf buf = opaque; /* just to make some compilers happy */ | 219 voidpf buf; |
223 ulg bsize = (ulg)items*size; | 220 ulg bsize = (ulg)items*size; |
224 | 221 |
| 222 (void)opaque; |
| 223 |
225 /* If we allocate less than 65520 bytes, we assume that farmalloc | 224 /* If we allocate less than 65520 bytes, we assume that farmalloc |
226 * will return a usable pointer which doesn't have to be normalized. | 225 * will return a usable pointer which doesn't have to be normalized. |
227 */ | 226 */ |
228 if (bsize < 65520L) { | 227 if (bsize < 65520L) { |
229 buf = farmalloc(bsize); | 228 buf = farmalloc(bsize); |
230 if (*(ush*)&buf != 0) return buf; | 229 if (*(ush*)&buf != 0) return buf; |
231 } else { | 230 } else { |
232 buf = farmalloc(bsize + 16L); | 231 buf = farmalloc(bsize + 16L); |
233 } | 232 } |
234 if (buf == NULL || next_ptr >= MAX_PTR) return NULL; | 233 if (buf == NULL || next_ptr >= MAX_PTR) return NULL; |
235 table[next_ptr].org_ptr = buf; | 234 table[next_ptr].org_ptr = buf; |
236 | 235 |
237 /* Normalize the pointer to seg:0 */ | 236 /* Normalize the pointer to seg:0 */ |
238 *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; | 237 *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; |
239 *(ush*)&buf = 0; | 238 *(ush*)&buf = 0; |
240 table[next_ptr++].new_ptr = buf; | 239 table[next_ptr++].new_ptr = buf; |
241 return buf; | 240 return buf; |
242 } | 241 } |
243 | 242 |
244 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) | 243 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) |
245 { | 244 { |
246 int n; | 245 int n; |
| 246 |
| 247 (void)opaque; |
| 248 |
247 if (*(ush*)&ptr != 0) { /* object < 64K */ | 249 if (*(ush*)&ptr != 0) { /* object < 64K */ |
248 farfree(ptr); | 250 farfree(ptr); |
249 return; | 251 return; |
250 } | 252 } |
251 /* Find the original pointer */ | 253 /* Find the original pointer */ |
252 for (n = 0; n < next_ptr; n++) { | 254 for (n = 0; n < next_ptr; n++) { |
253 if (ptr != table[n].new_ptr) continue; | 255 if (ptr != table[n].new_ptr) continue; |
254 | 256 |
255 farfree(table[n].org_ptr); | 257 farfree(table[n].org_ptr); |
256 while (++n < next_ptr) { | 258 while (++n < next_ptr) { |
257 table[n-1] = table[n]; | 259 table[n-1] = table[n]; |
258 } | 260 } |
259 next_ptr--; | 261 next_ptr--; |
260 return; | 262 return; |
261 } | 263 } |
262 ptr = opaque; /* just to make some compilers happy */ | |
263 Assert(0, "zcfree: ptr not found"); | 264 Assert(0, "zcfree: ptr not found"); |
264 } | 265 } |
265 | 266 |
266 #endif /* __TURBOC__ */ | 267 #endif /* __TURBOC__ */ |
267 | 268 |
268 | 269 |
269 #ifdef M_I86 | 270 #ifdef M_I86 |
270 /* Microsoft C in 16-bit mode */ | 271 /* Microsoft C in 16-bit mode */ |
271 | 272 |
272 # define MY_ZCALLOC | 273 # define MY_ZCALLOC |
273 | 274 |
274 #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) | 275 #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) |
275 # define _halloc halloc | 276 # define _halloc halloc |
276 # define _hfree hfree | 277 # define _hfree hfree |
277 #endif | 278 #endif |
278 | 279 |
279 voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) | 280 voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) |
280 { | 281 { |
281 if (opaque) opaque = 0; /* to make compiler happy */ | 282 (void)opaque; |
282 return _halloc((long)items, size); | 283 return _halloc((long)items, size); |
283 } | 284 } |
284 | 285 |
285 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) | 286 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) |
286 { | 287 { |
287 if (opaque) opaque = 0; /* to make compiler happy */ | 288 (void)opaque; |
288 _hfree(ptr); | 289 _hfree(ptr); |
289 } | 290 } |
290 | 291 |
291 #endif /* M_I86 */ | 292 #endif /* M_I86 */ |
292 | 293 |
293 #endif /* SYS16BIT */ | 294 #endif /* SYS16BIT */ |
294 | 295 |
295 | 296 |
296 #ifndef MY_ZCALLOC /* Any system without a special alloc function */ | 297 #ifndef MY_ZCALLOC /* Any system without a special alloc function */ |
297 | 298 |
298 #ifndef STDC | 299 #ifndef STDC |
299 extern voidp malloc OF((uInt size)); | 300 extern voidp malloc OF((uInt size)); |
300 extern voidp calloc OF((uInt items, uInt size)); | 301 extern voidp calloc OF((uInt items, uInt size)); |
301 extern void free OF((voidpf ptr)); | 302 extern void free OF((voidpf ptr)); |
302 #endif | 303 #endif |
303 | 304 |
304 voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) | 305 voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) |
305 voidpf opaque; | 306 voidpf opaque; |
306 unsigned items; | 307 unsigned items; |
307 unsigned size; | 308 unsigned size; |
308 { | 309 { |
309 if (opaque) items += size - size; /* make compiler happy */ | 310 (void)opaque; |
310 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : | 311 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : |
311 (voidpf)calloc(items, size); | 312 (voidpf)calloc(items, size); |
312 } | 313 } |
313 | 314 |
314 void ZLIB_INTERNAL zcfree (opaque, ptr) | 315 void ZLIB_INTERNAL zcfree (opaque, ptr) |
315 voidpf opaque; | 316 voidpf opaque; |
316 voidpf ptr; | 317 voidpf ptr; |
317 { | 318 { |
| 319 (void)opaque; |
318 free(ptr); | 320 free(ptr); |
319 if (opaque) return; /* make compiler happy */ | |
320 } | 321 } |
321 | 322 |
322 #endif /* MY_ZCALLOC */ | 323 #endif /* MY_ZCALLOC */ |
323 | 324 |
324 #endif /* !Z_SOLO */ | 325 #endif /* !Z_SOLO */ |
OLD | NEW |