1355d67fcSMatthew Dillon /* zutil.c -- target dependent utility functions for the compression library
2355d67fcSMatthew Dillon  * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
3355d67fcSMatthew Dillon  * For conditions of distribution and use, see copyright notice in zlib.h
4355d67fcSMatthew Dillon  */
5355d67fcSMatthew Dillon 
6355d67fcSMatthew Dillon /* @(#) $Id$ */
7355d67fcSMatthew Dillon 
8355d67fcSMatthew Dillon #include "hammer2_zlib_zutil.h"
9355d67fcSMatthew Dillon 
10355d67fcSMatthew Dillon #ifndef NO_DUMMY_DECL
11355d67fcSMatthew Dillon struct internal_state      {int dummy;}; /* for buggy compilers */
12355d67fcSMatthew Dillon #endif
13355d67fcSMatthew Dillon 
14355d67fcSMatthew Dillon z_const char * const z_errmsg[10] = {
15355d67fcSMatthew Dillon "need dictionary",     /* Z_NEED_DICT       2  */
16355d67fcSMatthew Dillon "stream end",          /* Z_STREAM_END      1  */
17355d67fcSMatthew Dillon "",                    /* Z_OK              0  */
18355d67fcSMatthew Dillon "file error",          /* Z_ERRNO         (-1) */
19355d67fcSMatthew Dillon "stream error",        /* Z_STREAM_ERROR  (-2) */
20355d67fcSMatthew Dillon "data error",          /* Z_DATA_ERROR    (-3) */
21355d67fcSMatthew Dillon "insufficient memory", /* Z_MEM_ERROR     (-4) */
22355d67fcSMatthew Dillon "buffer error",        /* Z_BUF_ERROR     (-5) */
23355d67fcSMatthew Dillon "incompatible version",/* Z_VERSION_ERROR (-6) */
24355d67fcSMatthew Dillon ""};
25355d67fcSMatthew Dillon 
26355d67fcSMatthew Dillon const char * zlibVersion(void);
27355d67fcSMatthew Dillon uLong zlibCompileFlags(void);
28355d67fcSMatthew Dillon const char * zError(int err);
29355d67fcSMatthew Dillon 
30355d67fcSMatthew Dillon const
31355d67fcSMatthew Dillon char*
zlibVersion(void)32355d67fcSMatthew Dillon zlibVersion(void)
33355d67fcSMatthew Dillon {
34355d67fcSMatthew Dillon     return ZLIB_VERSION;
35355d67fcSMatthew Dillon }
36355d67fcSMatthew Dillon 
37355d67fcSMatthew Dillon uLong
zlibCompileFlags(void)38355d67fcSMatthew Dillon zlibCompileFlags(void)
39355d67fcSMatthew Dillon {
40355d67fcSMatthew Dillon     uLong flags;
41355d67fcSMatthew Dillon 
42355d67fcSMatthew Dillon     flags = 0;
43355d67fcSMatthew Dillon     switch ((int)(sizeof(uInt))) {
44355d67fcSMatthew Dillon     case 2:     break;
45355d67fcSMatthew Dillon     case 4:     flags += 1;     break;
46355d67fcSMatthew Dillon     case 8:     flags += 2;     break;
47355d67fcSMatthew Dillon     default:    flags += 3;
48355d67fcSMatthew Dillon     }
49355d67fcSMatthew Dillon     switch ((int)(sizeof(uLong))) {
50355d67fcSMatthew Dillon     case 2:     break;
51355d67fcSMatthew Dillon     case 4:     flags += 1 << 2;        break;
52355d67fcSMatthew Dillon     case 8:     flags += 2 << 2;        break;
53355d67fcSMatthew Dillon     default:    flags += 3 << 2;
54355d67fcSMatthew Dillon     }
55355d67fcSMatthew Dillon     switch ((int)(sizeof(voidpf))) {
56355d67fcSMatthew Dillon     case 2:     break;
57355d67fcSMatthew Dillon     case 4:     flags += 1 << 4;        break;
58355d67fcSMatthew Dillon     case 8:     flags += 2 << 4;        break;
59355d67fcSMatthew Dillon     default:    flags += 3 << 4;
60355d67fcSMatthew Dillon     }
61355d67fcSMatthew Dillon     switch ((int)(sizeof(z_off_t))) {
62355d67fcSMatthew Dillon     case 2:     break;
63355d67fcSMatthew Dillon     case 4:     flags += 1 << 6;        break;
64355d67fcSMatthew Dillon     case 8:     flags += 2 << 6;        break;
65355d67fcSMatthew Dillon     default:    flags += 3 << 6;
66355d67fcSMatthew Dillon     }
67*a46112e5SSascha Wildner #ifdef H2_ZLIB_DEBUG
68355d67fcSMatthew Dillon     flags += 1 << 8;
69355d67fcSMatthew Dillon #endif
70355d67fcSMatthew Dillon #if defined(ASMV) || defined(ASMINF)
71355d67fcSMatthew Dillon     flags += 1 << 9;
72355d67fcSMatthew Dillon #endif
73355d67fcSMatthew Dillon #ifdef ZLIB_WINAPI
74355d67fcSMatthew Dillon     flags += 1 << 10;
75355d67fcSMatthew Dillon #endif
76355d67fcSMatthew Dillon #ifdef BUILDFIXED
77355d67fcSMatthew Dillon     flags += 1 << 12;
78355d67fcSMatthew Dillon #endif
79355d67fcSMatthew Dillon #ifdef DYNAMIC_CRC_TABLE
80355d67fcSMatthew Dillon     flags += 1 << 13;
81355d67fcSMatthew Dillon #endif
82355d67fcSMatthew Dillon #ifdef NO_GZCOMPRESS
83355d67fcSMatthew Dillon     flags += 1L << 16;
84355d67fcSMatthew Dillon #endif
85355d67fcSMatthew Dillon #ifdef NO_GZIP
86355d67fcSMatthew Dillon     flags += 1L << 17;
87355d67fcSMatthew Dillon #endif
88355d67fcSMatthew Dillon #ifdef PKZIP_BUG_WORKAROUND
89355d67fcSMatthew Dillon     flags += 1L << 20;
90355d67fcSMatthew Dillon #endif
91355d67fcSMatthew Dillon #ifdef FASTEST
92355d67fcSMatthew Dillon     flags += 1L << 21;
93355d67fcSMatthew Dillon #endif
94355d67fcSMatthew Dillon #if defined(STDC) || defined(Z_HAVE_STDARG_H)
95355d67fcSMatthew Dillon #  ifdef NO_vsnprintf
96355d67fcSMatthew Dillon     flags += 1L << 25;
97355d67fcSMatthew Dillon #    ifdef HAS_vsprintf_void
98355d67fcSMatthew Dillon     flags += 1L << 26;
99355d67fcSMatthew Dillon #    endif
100355d67fcSMatthew Dillon #  else
101355d67fcSMatthew Dillon #    ifdef HAS_vsnprintf_void
102355d67fcSMatthew Dillon     flags += 1L << 26;
103355d67fcSMatthew Dillon #    endif
104355d67fcSMatthew Dillon #  endif
105355d67fcSMatthew Dillon #else
106355d67fcSMatthew Dillon     flags += 1L << 24;
107355d67fcSMatthew Dillon #  ifdef NO_snprintf
108355d67fcSMatthew Dillon     flags += 1L << 25;
109355d67fcSMatthew Dillon #    ifdef HAS_sprintf_void
110355d67fcSMatthew Dillon     flags += 1L << 26;
111355d67fcSMatthew Dillon #    endif
112355d67fcSMatthew Dillon #  else
113355d67fcSMatthew Dillon #    ifdef HAS_snprintf_void
114355d67fcSMatthew Dillon     flags += 1L << 26;
115355d67fcSMatthew Dillon #    endif
116355d67fcSMatthew Dillon #  endif
117355d67fcSMatthew Dillon #endif
118355d67fcSMatthew Dillon     return flags;
119355d67fcSMatthew Dillon }
120355d67fcSMatthew Dillon 
121*a46112e5SSascha Wildner #ifdef H2_ZLIB_DEBUG
122355d67fcSMatthew Dillon 
123355d67fcSMatthew Dillon #  ifndef verbose
124355d67fcSMatthew Dillon #    define verbose 0
125355d67fcSMatthew Dillon #  endif
126355d67fcSMatthew Dillon int ZLIB_INTERNAL z_verbose = verbose;
127355d67fcSMatthew Dillon 
z_error(char * m)128355d67fcSMatthew Dillon void ZLIB_INTERNAL z_error (char *m)
129355d67fcSMatthew Dillon {
13089202d69Szrj #if defined(_KERNEL)
13189202d69Szrj     panic("h2 %s: %s", __func__, m);
13289202d69Szrj #else
133355d67fcSMatthew Dillon     fprintf(stderr, "%s\n", m);
134355d67fcSMatthew Dillon     exit(1);
13589202d69Szrj #endif
136355d67fcSMatthew Dillon }
137355d67fcSMatthew Dillon #endif
138355d67fcSMatthew Dillon 
139355d67fcSMatthew Dillon /* exported to allow conversion of error code to string for compress() and
140355d67fcSMatthew Dillon  * uncompress()
141355d67fcSMatthew Dillon  */
142355d67fcSMatthew Dillon const
143355d67fcSMatthew Dillon char*
zError(int err)144355d67fcSMatthew Dillon zError(int err)
145355d67fcSMatthew Dillon {
146355d67fcSMatthew Dillon     return ERR_MSG(err);
147355d67fcSMatthew Dillon }
148355d67fcSMatthew Dillon 
149355d67fcSMatthew Dillon #ifndef HAVE_MEMCPY
150355d67fcSMatthew Dillon 
151355d67fcSMatthew Dillon void
152355d67fcSMatthew Dillon ZLIB_INTERNAL
zmemcpy(Bytef * dest,const Bytef * source,uInt len)153355d67fcSMatthew Dillon zmemcpy(Bytef* dest, const Bytef* source, uInt  len)
154355d67fcSMatthew Dillon {
155355d67fcSMatthew Dillon     if (len == 0) return;
156355d67fcSMatthew Dillon     do {
157355d67fcSMatthew Dillon         *dest++ = *source++; /* ??? to be unrolled */
158355d67fcSMatthew Dillon     } while (--len != 0);
159355d67fcSMatthew Dillon }
160355d67fcSMatthew Dillon 
161355d67fcSMatthew Dillon int
162355d67fcSMatthew Dillon ZLIB_INTERNAL
zmemcmp(const Bytef * s1,const Bytef * s2,uInt len)163355d67fcSMatthew Dillon zmemcmp(const Bytef* s1, const Bytef* s2, uInt len)
164355d67fcSMatthew Dillon {
165355d67fcSMatthew Dillon     uInt j;
166355d67fcSMatthew Dillon 
167355d67fcSMatthew Dillon     for (j = 0; j < len; j++) {
168355d67fcSMatthew Dillon         if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
169355d67fcSMatthew Dillon     }
170355d67fcSMatthew Dillon     return 0;
171355d67fcSMatthew Dillon }
172355d67fcSMatthew Dillon 
173355d67fcSMatthew Dillon void
174355d67fcSMatthew Dillon ZLIB_INTERNAL
zmemzero(Bytef * dest,uInt len)175355d67fcSMatthew Dillon zmemzero(Bytef* dest, uInt len)
176355d67fcSMatthew Dillon {
177355d67fcSMatthew Dillon     if (len == 0) return;
178355d67fcSMatthew Dillon     do {
179355d67fcSMatthew Dillon         *dest++ = 0;  /* ??? to be unrolled */
180355d67fcSMatthew Dillon     } while (--len != 0);
181355d67fcSMatthew Dillon }
182355d67fcSMatthew Dillon #endif
183