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