lzo: update to 2.09
[tomato.git] / release / src / router / lzo / lzotest / wrapmisc.h
blob12c480911ac19ee20d660e83ce30ac762bbb2ac2
1 /* wrapmisc.h -- misc wrapper functions for the test driver
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer
6 All Rights Reserved.
8 The LZO library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 The LZO library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the LZO library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
25 http://www.oberhumer.com/opensource/lzo/
29 /*************************************************************************
30 // compression levels of zlib
31 **************************************************************************/
33 #if defined(ALG_ZLIB)
35 #define ZLIB_MEM_COMPRESS 0
36 #define ZLIB_MEM_DECOMPRESS 0
38 static
39 int zlib_compress ( const m_bytep src, m_uint src_len,
40 m_bytep dst, m_uintp dst_len,
41 m_voidp wrkmem,
42 int method, int compression_level )
44 int err;
45 uLong destLen;
47 assert(method == Z_DEFLATED);
48 destLen = (uLong) *dst_len;
49 err = compress2(dst, &destLen, src, (uLong) src_len, compression_level);
50 *dst_len = destLen;
51 LZO_UNUSED(method);
52 LZO_UNUSED(wrkmem);
53 return err;
57 M_PRIVATE(int)
58 zlib_decompress ( const m_bytep src, m_uint src_len,
59 m_bytep dst, m_uintp dst_len,
60 m_voidp wrkmem )
62 int err;
63 uLong destLen;
65 destLen = (uLong) *dst_len;
66 err = uncompress(dst, &destLen, src, (uLong) src_len);
67 *dst_len = destLen;
68 LZO_UNUSED(wrkmem);
69 return err;
73 M_PRIVATE(int)
74 zlib_8_1_compress ( const m_bytep src, m_uint src_len,
75 m_bytep dst, m_uintp dst_len,
76 m_voidp wrkmem )
77 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,1); }
79 M_PRIVATE(int)
80 zlib_8_2_compress ( const m_bytep src, m_uint src_len,
81 m_bytep dst, m_uintp dst_len,
82 m_voidp wrkmem )
83 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,2); }
85 M_PRIVATE(int)
86 zlib_8_3_compress ( const m_bytep src, m_uint src_len,
87 m_bytep dst, m_uintp dst_len,
88 m_voidp wrkmem )
89 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,3); }
91 M_PRIVATE(int)
92 zlib_8_4_compress ( const m_bytep src, m_uint src_len,
93 m_bytep dst, m_uintp dst_len,
94 m_voidp wrkmem )
95 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,4); }
97 M_PRIVATE(int)
98 zlib_8_5_compress ( const m_bytep src, m_uint src_len,
99 m_bytep dst, m_uintp dst_len,
100 m_voidp wrkmem )
101 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,5); }
103 M_PRIVATE(int)
104 zlib_8_6_compress ( const m_bytep src, m_uint src_len,
105 m_bytep dst, m_uintp dst_len,
106 m_voidp wrkmem )
107 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,6); }
109 M_PRIVATE(int)
110 zlib_8_7_compress ( const m_bytep src, m_uint src_len,
111 m_bytep dst, m_uintp dst_len,
112 m_voidp wrkmem )
113 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,7); }
115 M_PRIVATE(int)
116 zlib_8_8_compress ( const m_bytep src, m_uint src_len,
117 m_bytep dst, m_uintp dst_len,
118 m_voidp wrkmem )
119 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,8); }
121 M_PRIVATE(int)
122 zlib_8_9_compress ( const m_bytep src, m_uint src_len,
123 m_bytep dst, m_uintp dst_len,
124 m_voidp wrkmem )
125 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,9); }
128 #endif /* ALG_ZLIB */
131 /*************************************************************************
132 // compression levels of bzip2
133 **************************************************************************/
135 #if defined(ALG_BZIP2)
137 #define BZIP2_MEM_COMPRESS 0
138 #define BZIP2_MEM_DECOMPRESS 0
140 static
141 int bzip2_compress ( const m_bytep src, m_uint src_len,
142 m_bytep dst, m_uintp dst_len,
143 m_voidp wrkmem,
144 int compression_level )
146 int err;
147 unsigned destLen;
148 union { const m_bytep csrc; char *src; } u;
150 u.csrc = src; /* UNCONST */
151 destLen = *dst_len;
152 err = BZ2_bzBuffToBuffCompress((char*)dst, &destLen, u.src, src_len, compression_level, 0, 0);
153 *dst_len = destLen;
154 LZO_UNUSED(wrkmem);
155 return err;
159 M_PRIVATE(int)
160 bzip2_decompress ( const m_bytep src, m_uint src_len,
161 m_bytep dst, m_uintp dst_len,
162 m_voidp wrkmem )
164 int err;
165 unsigned destLen;
166 union { const m_bytep csrc; char *src; } u;
168 u.csrc = src; /* UNCONST */
169 destLen = *dst_len;
170 err = BZ2_bzBuffToBuffDecompress((char*)dst, &destLen, u.src, src_len, 0, 0);
171 *dst_len = destLen;
172 LZO_UNUSED(wrkmem);
173 return err;
177 M_PRIVATE(int)
178 bzip2_1_compress ( const m_bytep src, m_uint src_len,
179 m_bytep dst, m_uintp dst_len,
180 m_voidp wrkmem )
181 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,1); }
183 M_PRIVATE(int)
184 bzip2_2_compress ( const m_bytep src, m_uint src_len,
185 m_bytep dst, m_uintp dst_len,
186 m_voidp wrkmem )
187 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,2); }
189 M_PRIVATE(int)
190 bzip2_3_compress ( const m_bytep src, m_uint src_len,
191 m_bytep dst, m_uintp dst_len,
192 m_voidp wrkmem )
193 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,3); }
195 M_PRIVATE(int)
196 bzip2_4_compress ( const m_bytep src, m_uint src_len,
197 m_bytep dst, m_uintp dst_len,
198 m_voidp wrkmem )
199 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,4); }
201 M_PRIVATE(int)
202 bzip2_5_compress ( const m_bytep src, m_uint src_len,
203 m_bytep dst, m_uintp dst_len,
204 m_voidp wrkmem )
205 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,5); }
207 M_PRIVATE(int)
208 bzip2_6_compress ( const m_bytep src, m_uint src_len,
209 m_bytep dst, m_uintp dst_len,
210 m_voidp wrkmem )
211 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,6); }
213 M_PRIVATE(int)
214 bzip2_7_compress ( const m_bytep src, m_uint src_len,
215 m_bytep dst, m_uintp dst_len,
216 m_voidp wrkmem )
217 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,7); }
219 M_PRIVATE(int)
220 bzip2_8_compress ( const m_bytep src, m_uint src_len,
221 m_bytep dst, m_uintp dst_len,
222 m_voidp wrkmem )
223 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,8); }
225 M_PRIVATE(int)
226 bzip2_9_compress ( const m_bytep src, m_uint src_len,
227 m_bytep dst, m_uintp dst_len,
228 m_voidp wrkmem )
229 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,9); }
232 #endif /* ALG_BZIP2 */
235 /*************************************************************************
236 // other wrappers (for benchmarking the checksum algorithms)
237 **************************************************************************/
239 #if defined(ALG_ZLIB)
241 M_PRIVATE(int)
242 zlib_adler32_x_compress ( const m_bytep src, m_uint src_len,
243 m_bytep dst, m_uintp dst_len,
244 m_voidp wrkmem )
246 uLong adler;
247 adler = adler32(1L, src, (uInt) src_len);
248 *dst_len = src_len;
249 LZO_UNUSED(adler);
250 LZO_UNUSED(dst);
251 LZO_UNUSED(wrkmem);
252 return 0;
256 M_PRIVATE(int)
257 zlib_crc32_x_compress ( const m_bytep src, m_uint src_len,
258 m_bytep dst, m_uintp dst_len,
259 m_voidp wrkmem )
261 uLong crc;
262 crc = crc32(0L, src, (uInt) src_len);
263 *dst_len = src_len;
264 LZO_UNUSED(crc);
265 LZO_UNUSED(dst);
266 LZO_UNUSED(wrkmem);
267 return 0;
270 #endif /* ALG_ZLIB */
273 /* vim:set ts=4 sw=4 et: */