comparison zlib/zutil.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents ae3a4bfb450b
children
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
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 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: zutil.c,v 1.1.1.2 2002/03/11 21:53:27 tromey Exp $ */ 6 /* @(#) $Id: zutil.c,v 1.1.1.2 2002/03/11 21:53:27 tromey Exp $ */
7 7
8 #include "zutil.h" 8 #include "zutil.h"
9 9 #ifndef Z_SOLO
10 #ifndef NO_DUMMY_DECL 10 # include "gzguts.h"
11 struct internal_state {int dummy;}; /* for buggy compilers */ 11 #endif
12 #endif 12
13 13 z_const char * const z_errmsg[10] = {
14 const char * const z_errmsg[10] = { 14 (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */
15 "need dictionary", /* Z_NEED_DICT 2 */ 15 (z_const char *)"stream end", /* Z_STREAM_END 1 */
16 "stream end", /* Z_STREAM_END 1 */ 16 (z_const char *)"", /* Z_OK 0 */
17 "", /* Z_OK 0 */ 17 (z_const char *)"file error", /* Z_ERRNO (-1) */
18 "file error", /* Z_ERRNO (-1) */ 18 (z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */
19 "stream error", /* Z_STREAM_ERROR (-2) */ 19 (z_const char *)"data error", /* Z_DATA_ERROR (-3) */
20 "data error", /* Z_DATA_ERROR (-3) */ 20 (z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */
21 "insufficient memory", /* Z_MEM_ERROR (-4) */ 21 (z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */
22 "buffer error", /* Z_BUF_ERROR (-5) */ 22 (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
23 "incompatible version",/* Z_VERSION_ERROR (-6) */ 23 (z_const char *)""
24 ""}; 24 };
25 25
26 26
27 const char * ZEXPORT zlibVersion() 27 const char * ZEXPORT zlibVersion()
28 { 28 {
29 return ZLIB_VERSION; 29 return ZLIB_VERSION;
32 uLong ZEXPORT zlibCompileFlags() 32 uLong ZEXPORT zlibCompileFlags()
33 { 33 {
34 uLong flags; 34 uLong flags;
35 35
36 flags = 0; 36 flags = 0;
37 switch (sizeof(uInt)) { 37 switch ((int)(sizeof(uInt))) {
38 case 2: break; 38 case 2: break;
39 case 4: flags += 1; break; 39 case 4: flags += 1; break;
40 case 8: flags += 2; break; 40 case 8: flags += 2; break;
41 default: flags += 3; 41 default: flags += 3;
42 } 42 }
43 switch (sizeof(uLong)) { 43 switch ((int)(sizeof(uLong))) {
44 case 2: break; 44 case 2: break;
45 case 4: flags += 1 << 2; break; 45 case 4: flags += 1 << 2; break;
46 case 8: flags += 2 << 2; break; 46 case 8: flags += 2 << 2; break;
47 default: flags += 3 << 2; 47 default: flags += 3 << 2;
48 } 48 }
49 switch (sizeof(voidpf)) { 49 switch ((int)(sizeof(voidpf))) {
50 case 2: break; 50 case 2: break;
51 case 4: flags += 1 << 4; break; 51 case 4: flags += 1 << 4; break;
52 case 8: flags += 2 << 4; break; 52 case 8: flags += 2 << 4; break;
53 default: flags += 3 << 4; 53 default: flags += 3 << 4;
54 } 54 }
55 switch (sizeof(z_off_t)) { 55 switch ((int)(sizeof(z_off_t))) {
56 case 2: break; 56 case 2: break;
57 case 4: flags += 1 << 6; break; 57 case 4: flags += 1 << 6; break;
58 case 8: flags += 2 << 6; break; 58 case 8: flags += 2 << 6; break;
59 default: flags += 3 << 6; 59 default: flags += 3 << 6;
60 } 60 }
61 #ifdef DEBUG 61 #ifdef ZLIB_DEBUG
62 flags += 1 << 8; 62 flags += 1 << 8;
63 #endif 63 #endif
64 #if defined(ASMV) || defined(ASMINF) 64 #if defined(ASMV) || defined(ASMINF)
65 flags += 1 << 9; 65 flags += 1 << 9;
66 #endif 66 #endif
83 flags += 1L << 20; 83 flags += 1L << 20;
84 #endif 84 #endif
85 #ifdef FASTEST 85 #ifdef FASTEST
86 flags += 1L << 21; 86 flags += 1L << 21;
87 #endif 87 #endif
88 #ifdef STDC 88 #if defined(STDC) || defined(Z_HAVE_STDARG_H)
89 # ifdef NO_vsnprintf 89 # ifdef NO_vsnprintf
90 flags += 1L << 25; 90 flags += 1L << 25;
91 # ifdef HAS_vsprintf_void 91 # ifdef HAS_vsprintf_void
92 flags += 1L << 26; 92 flags += 1L << 26;
93 # endif 93 # endif
94 # else 94 # else
95 # ifdef HAS_vsnprintf_void 95 # ifdef HAS_vsnprintf_void
96 flags += 1L << 26; 96 flags += 1L << 26;
97 # endif 97 # endif
98 # endif 98 # endif
99 #else 99 #else
100 flags += 1L << 24; 100 flags += 1L << 24;
101 # ifdef NO_snprintf 101 # ifdef NO_snprintf
102 flags += 1L << 25; 102 flags += 1L << 25;
103 # ifdef HAS_sprintf_void 103 # ifdef HAS_sprintf_void
104 flags += 1L << 26; 104 flags += 1L << 26;
105 # endif 105 # endif
106 # else 106 # else
107 # ifdef HAS_snprintf_void 107 # ifdef HAS_snprintf_void
108 flags += 1L << 26; 108 flags += 1L << 26;
109 # endif 109 # endif
110 # endif 110 # endif
111 #endif 111 #endif
112 return flags; 112 return flags;
113 } 113 }
114 114
115 #ifdef DEBUG 115 #ifdef ZLIB_DEBUG
116 116 #include <stdlib.h>
117 # ifndef verbose 117 # ifndef verbose
118 # define verbose 0 118 # define verbose 0
119 # endif 119 # endif
120 int z_verbose = verbose; 120 int ZLIB_INTERNAL z_verbose = verbose;
121 121
122 void z_error (m) 122 void ZLIB_INTERNAL z_error (m)
123 char *m; 123 char *m;
124 { 124 {
125 fprintf(stderr, "%s\n", m); 125 fprintf(stderr, "%s\n", m);
126 exit(1); 126 exit(1);
127 } 127 }
144 int errno = 0; 144 int errno = 0;
145 #endif 145 #endif
146 146
147 #ifndef HAVE_MEMCPY 147 #ifndef HAVE_MEMCPY
148 148
149 void zmemcpy(dest, source, len) 149 void ZLIB_INTERNAL zmemcpy(dest, source, len)
150 Bytef* dest; 150 Bytef* dest;
151 const Bytef* source; 151 const Bytef* source;
152 uInt len; 152 uInt len;
153 { 153 {
154 if (len == 0) return; 154 if (len == 0) return;
155 do { 155 do {
156 *dest++ = *source++; /* ??? to be unrolled */ 156 *dest++ = *source++; /* ??? to be unrolled */
157 } while (--len != 0); 157 } while (--len != 0);
158 } 158 }
159 159
160 int zmemcmp(s1, s2, len) 160 int ZLIB_INTERNAL zmemcmp(s1, s2, len)
161 const Bytef* s1; 161 const Bytef* s1;
162 const Bytef* s2; 162 const Bytef* s2;
163 uInt len; 163 uInt len;
164 { 164 {
165 uInt j; 165 uInt j;
168 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 168 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
169 } 169 }
170 return 0; 170 return 0;
171 } 171 }
172 172
173 void zmemzero(dest, len) 173 void ZLIB_INTERNAL zmemzero(dest, len)
174 Bytef* dest; 174 Bytef* dest;
175 uInt len; 175 uInt len;
176 { 176 {
177 if (len == 0) return; 177 if (len == 0) return;
178 do { 178 do {
179 *dest++ = 0; /* ??? to be unrolled */ 179 *dest++ = 0; /* ??? to be unrolled */
180 } while (--len != 0); 180 } while (--len != 0);
181 } 181 }
182 #endif 182 #endif
183 183
184 #ifndef Z_SOLO
184 185
185 #ifdef SYS16BIT 186 #ifdef SYS16BIT
186 187
187 #ifdef __TURBOC__ 188 #ifdef __TURBOC__
188 /* Turbo C in 16-bit mode */ 189 /* Turbo C in 16-bit mode */
211 * 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
212 * protected from concurrent access. This hack doesn't work anyway on 213 * protected from concurrent access. This hack doesn't work anyway on
213 * a protected system like OS/2. Use Microsoft C instead. 214 * a protected system like OS/2. Use Microsoft C instead.
214 */ 215 */
215 216
216 voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 217 voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
217 { 218 {
218 voidpf buf = opaque; /* just to make some compilers happy */ 219 voidpf buf;
219 ulg bsize = (ulg)items*size; 220 ulg bsize = (ulg)items*size;
221
222 (void)opaque;
220 223
221 /* If we allocate less than 65520 bytes, we assume that farmalloc 224 /* If we allocate less than 65520 bytes, we assume that farmalloc
222 * 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.
223 */ 226 */
224 if (bsize < 65520L) { 227 if (bsize < 65520L) {
235 *(ush*)&buf = 0; 238 *(ush*)&buf = 0;
236 table[next_ptr++].new_ptr = buf; 239 table[next_ptr++].new_ptr = buf;
237 return buf; 240 return buf;
238 } 241 }
239 242
240 void zcfree (voidpf opaque, voidpf ptr) 243 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
241 { 244 {
242 int n; 245 int n;
246
247 (void)opaque;
248
243 if (*(ush*)&ptr != 0) { /* object < 64K */ 249 if (*(ush*)&ptr != 0) { /* object < 64K */
244 farfree(ptr); 250 farfree(ptr);
245 return; 251 return;
246 } 252 }
247 /* Find the original pointer */ 253 /* Find the original pointer */
253 table[n-1] = table[n]; 259 table[n-1] = table[n];
254 } 260 }
255 next_ptr--; 261 next_ptr--;
256 return; 262 return;
257 } 263 }
258 ptr = opaque; /* just to make some compilers happy */
259 Assert(0, "zcfree: ptr not found"); 264 Assert(0, "zcfree: ptr not found");
260 } 265 }
261 266
262 #endif /* __TURBOC__ */ 267 #endif /* __TURBOC__ */
263 268
270 #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 275 #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
271 # define _halloc halloc 276 # define _halloc halloc
272 # define _hfree hfree 277 # define _hfree hfree
273 #endif 278 #endif
274 279
275 voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 280 voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
276 { 281 {
277 if (opaque) opaque = 0; /* to make compiler happy */ 282 (void)opaque;
278 return _halloc((long)items, size); 283 return _halloc((long)items, size);
279 } 284 }
280 285
281 void zcfree (voidpf opaque, voidpf ptr) 286 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
282 { 287 {
283 if (opaque) opaque = 0; /* to make compiler happy */ 288 (void)opaque;
284 _hfree(ptr); 289 _hfree(ptr);
285 } 290 }
286 291
287 #endif /* M_I86 */ 292 #endif /* M_I86 */
288 293
295 extern voidp malloc OF((uInt size)); 300 extern voidp malloc OF((uInt size));
296 extern voidp calloc OF((uInt items, uInt size)); 301 extern voidp calloc OF((uInt items, uInt size));
297 extern void free OF((voidpf ptr)); 302 extern void free OF((voidpf ptr));
298 #endif 303 #endif
299 304
300 voidpf zcalloc (opaque, items, size) 305 voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
301 voidpf opaque; 306 voidpf opaque;
302 unsigned items; 307 unsigned items;
303 unsigned size; 308 unsigned size;
304 { 309 {
305 if (opaque) items += size - size; /* make compiler happy */ 310 (void)opaque;
306 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : 311 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
307 (voidpf)calloc(items, size); 312 (voidpf)calloc(items, size);
308 } 313 }
309 314
310 void zcfree (opaque, ptr) 315 void ZLIB_INTERNAL zcfree (opaque, ptr)
311 voidpf opaque; 316 voidpf opaque;
312 voidpf ptr; 317 voidpf ptr;
313 { 318 {
319 (void)opaque;
314 free(ptr); 320 free(ptr);
315 if (opaque) return; /* make compiler happy */
316 } 321 }
317 322
318 #endif /* MY_ZCALLOC */ 323 #endif /* MY_ZCALLOC */
324
325 #endif /* !Z_SOLO */