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*
32 zlibVersion(void)
33 {
34     return ZLIB_VERSION;
35 }
36 
37 uLong
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 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 DEBUG
122 
123 #  ifndef verbose
124 #    define verbose 0
125 #  endif
126 int ZLIB_INTERNAL z_verbose = verbose;
127 
128 void ZLIB_INTERNAL z_error (char *m)
129 {
130     fprintf(stderr, "%s\n", m);
131     exit(1);
132 }
133 #endif
134 
135 /* exported to allow conversion of error code to string for compress() and
136  * uncompress()
137  */
138 const
139 char*
140 zError(int err)
141 {
142     return ERR_MSG(err);
143 }
144 
145 #ifndef HAVE_MEMCPY
146 
147 void
148 ZLIB_INTERNAL
149 zmemcpy(Bytef* dest, const Bytef* source, uInt  len)
150 {
151     if (len == 0) return;
152     do {
153         *dest++ = *source++; /* ??? to be unrolled */
154     } while (--len != 0);
155 }
156 
157 int
158 ZLIB_INTERNAL
159 zmemcmp(const Bytef* s1, const Bytef* s2, uInt len)
160 {
161     uInt j;
162 
163     for (j = 0; j < len; j++) {
164         if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
165     }
166     return 0;
167 }
168 
169 void
170 ZLIB_INTERNAL
171 zmemzero(Bytef* dest, uInt len)
172 {
173     if (len == 0) return;
174     do {
175         *dest++ = 0;  /* ??? to be unrolled */
176     } while (--len != 0);
177 }
178 #endif
179