1 /* zutil.c -- target dependent utility functions for the compression library
2 * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6 /* @(#) $Id$ */
7
8 #include "hammer2_zlib_zutil.h"
9
10 #ifndef NO_DUMMY_DECL
11 struct internal_state {int dummy;}; /* for buggy compilers */
12 #endif
13
14 z_const char * const z_errmsg[10] = {
15 "need dictionary", /* Z_NEED_DICT 2 */
16 "stream end", /* Z_STREAM_END 1 */
17 "", /* Z_OK 0 */
18 "file error", /* Z_ERRNO (-1) */
19 "stream error", /* Z_STREAM_ERROR (-2) */
20 "data error", /* Z_DATA_ERROR (-3) */
21 "insufficient memory", /* Z_MEM_ERROR (-4) */
22 "buffer error", /* Z_BUF_ERROR (-5) */
23 "incompatible version",/* Z_VERSION_ERROR (-6) */
24 ""};
25
26 const char * zlibVersion(void);
27 uLong zlibCompileFlags(void);
28 const char * zError(int err);
29
30 const
31 char*
zlibVersion(void)32 zlibVersion(void)
33 {
34 return ZLIB_VERSION;
35 }
36
37 uLong
zlibCompileFlags(void)38 zlibCompileFlags(void)
39 {
40 uLong flags;
41
42 flags = 0;
43 switch ((int)(sizeof(uInt))) {
44 case 2: break;
45 case 4: flags += 1; break;
46 case 8: flags += 2; break;
47 default: flags += 3;
48 }
49 switch ((int)(sizeof(uLong))) {
50 case 2: break;
51 case 4: flags += 1 << 2; break;
52 case 8: flags += 2 << 2; break;
53 default: flags += 3 << 2;
54 }
55 switch ((int)(sizeof(voidpf))) {
56 case 2: break;
57 case 4: flags += 1 << 4; break;
58 case 8: flags += 2 << 4; break;
59 default: flags += 3 << 4;
60 }
61 switch ((int)(sizeof(z_off_t))) {
62 case 2: break;
63 case 4: flags += 1 << 6; break;
64 case 8: flags += 2 << 6; break;
65 default: flags += 3 << 6;
66 }
67 #ifdef H2_ZLIB_DEBUG
68 flags += 1 << 8;
69 #endif
70 #if defined(ASMV) || defined(ASMINF)
71 flags += 1 << 9;
72 #endif
73 #ifdef ZLIB_WINAPI
74 flags += 1 << 10;
75 #endif
76 #ifdef BUILDFIXED
77 flags += 1 << 12;
78 #endif
79 #ifdef DYNAMIC_CRC_TABLE
80 flags += 1 << 13;
81 #endif
82 #ifdef NO_GZCOMPRESS
83 flags += 1L << 16;
84 #endif
85 #ifdef NO_GZIP
86 flags += 1L << 17;
87 #endif
88 #ifdef PKZIP_BUG_WORKAROUND
89 flags += 1L << 20;
90 #endif
91 #ifdef FASTEST
92 flags += 1L << 21;
93 #endif
94 #if defined(STDC) || defined(Z_HAVE_STDARG_H)
95 # ifdef NO_vsnprintf
96 flags += 1L << 25;
97 # ifdef HAS_vsprintf_void
98 flags += 1L << 26;
99 # endif
100 # else
101 # ifdef HAS_vsnprintf_void
102 flags += 1L << 26;
103 # endif
104 # endif
105 #else
106 flags += 1L << 24;
107 # ifdef NO_snprintf
108 flags += 1L << 25;
109 # ifdef HAS_sprintf_void
110 flags += 1L << 26;
111 # endif
112 # else
113 # ifdef HAS_snprintf_void
114 flags += 1L << 26;
115 # endif
116 # endif
117 #endif
118 return flags;
119 }
120
121 #ifdef H2_ZLIB_DEBUG
122
123 # ifndef verbose
124 # define verbose 0
125 # endif
126 int ZLIB_INTERNAL z_verbose = verbose;
127
z_error(char * m)128 void ZLIB_INTERNAL z_error (char *m)
129 {
130 #if defined(_KERNEL)
131 panic("h2 %s: %s", __func__, m);
132 #else
133 fprintf(stderr, "%s\n", m);
134 exit(1);
135 #endif
136 }
137 #endif
138
139 /* exported to allow conversion of error code to string for compress() and
140 * uncompress()
141 */
142 const
143 char*
zError(int err)144 zError(int err)
145 {
146 return ERR_MSG(err);
147 }
148
149 #ifndef HAVE_MEMCPY
150
151 void
152 ZLIB_INTERNAL
zmemcpy(Bytef * dest,const Bytef * source,uInt len)153 zmemcpy(Bytef* dest, const Bytef* source, uInt len)
154 {
155 if (len == 0) return;
156 do {
157 *dest++ = *source++; /* ??? to be unrolled */
158 } while (--len != 0);
159 }
160
161 int
162 ZLIB_INTERNAL
zmemcmp(const Bytef * s1,const Bytef * s2,uInt len)163 zmemcmp(const Bytef* s1, const Bytef* s2, uInt len)
164 {
165 uInt j;
166
167 for (j = 0; j < len; j++) {
168 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
169 }
170 return 0;
171 }
172
173 void
174 ZLIB_INTERNAL
zmemzero(Bytef * dest,uInt len)175 zmemzero(Bytef* dest, uInt len)
176 {
177 if (len == 0) return;
178 do {
179 *dest++ = 0; /* ??? to be unrolled */
180 } while (--len != 0);
181 }
182 #endif
183