Updates to Tomato RAF including NGINX && PHP
[tomato.git] / release / src / router / lzo / lzotest / wrapmisc.h
blob559ffac37db5615f4d2ec8bd24fee8dbb7bf0288
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) 2011 Markus Franz Xaver Johannes Oberhumer
6 Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
7 Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
8 Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
9 Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
10 Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
11 Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
12 Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
13 Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
14 Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
15 Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
16 Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
17 Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
18 Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
19 Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
20 Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
21 All Rights Reserved.
23 The LZO library is free software; you can redistribute it and/or
24 modify it under the terms of the GNU General Public License as
25 published by the Free Software Foundation; either version 2 of
26 the License, or (at your option) any later version.
28 The LZO library is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with the LZO library; see the file COPYING.
35 If not, write to the Free Software Foundation, Inc.,
36 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
38 Markus F.X.J. Oberhumer
39 <markus@oberhumer.com>
40 http://www.oberhumer.com/opensource/lzo/
44 /*************************************************************************
45 // compression levels of zlib
46 **************************************************************************/
48 #if defined(ALG_ZLIB)
50 #define ZLIB_MEM_COMPRESS 0
51 #define ZLIB_MEM_DECOMPRESS 0
53 static
54 int zlib_compress ( const m_bytep src, m_uint src_len,
55 m_bytep dst, m_uintp dst_len,
56 m_voidp wrkmem,
57 int method, int compression_level )
59 int err;
60 uLong destLen;
62 assert(method == Z_DEFLATED);
63 destLen = (uLong) *dst_len;
64 err = compress2(dst, &destLen, src, (uLong) src_len, compression_level);
65 *dst_len = destLen;
66 LZO_UNUSED(method);
67 LZO_UNUSED(wrkmem);
68 return err;
72 M_PRIVATE(int)
73 zlib_decompress ( const m_bytep src, m_uint src_len,
74 m_bytep dst, m_uintp dst_len,
75 m_voidp wrkmem )
77 int err;
78 uLong destLen;
80 destLen = (uLong) *dst_len;
81 err = uncompress(dst, &destLen, src, (uLong) src_len);
82 *dst_len = destLen;
83 LZO_UNUSED(wrkmem);
84 return err;
88 M_PRIVATE(int)
89 zlib_8_1_compress ( const m_bytep src, m_uint src_len,
90 m_bytep dst, m_uintp dst_len,
91 m_voidp wrkmem )
92 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,1); }
94 M_PRIVATE(int)
95 zlib_8_2_compress ( const m_bytep src, m_uint src_len,
96 m_bytep dst, m_uintp dst_len,
97 m_voidp wrkmem )
98 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,2); }
100 M_PRIVATE(int)
101 zlib_8_3_compress ( const m_bytep src, m_uint src_len,
102 m_bytep dst, m_uintp dst_len,
103 m_voidp wrkmem )
104 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,3); }
106 M_PRIVATE(int)
107 zlib_8_4_compress ( const m_bytep src, m_uint src_len,
108 m_bytep dst, m_uintp dst_len,
109 m_voidp wrkmem )
110 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,4); }
112 M_PRIVATE(int)
113 zlib_8_5_compress ( const m_bytep src, m_uint src_len,
114 m_bytep dst, m_uintp dst_len,
115 m_voidp wrkmem )
116 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,5); }
118 M_PRIVATE(int)
119 zlib_8_6_compress ( const m_bytep src, m_uint src_len,
120 m_bytep dst, m_uintp dst_len,
121 m_voidp wrkmem )
122 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,6); }
124 M_PRIVATE(int)
125 zlib_8_7_compress ( const m_bytep src, m_uint src_len,
126 m_bytep dst, m_uintp dst_len,
127 m_voidp wrkmem )
128 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,7); }
130 M_PRIVATE(int)
131 zlib_8_8_compress ( const m_bytep src, m_uint src_len,
132 m_bytep dst, m_uintp dst_len,
133 m_voidp wrkmem )
134 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,8); }
136 M_PRIVATE(int)
137 zlib_8_9_compress ( const m_bytep src, m_uint src_len,
138 m_bytep dst, m_uintp dst_len,
139 m_voidp wrkmem )
140 { return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,9); }
143 #endif /* ALG_ZLIB */
146 /*************************************************************************
147 // compression levels of bzip2
148 **************************************************************************/
150 #if defined(ALG_BZIP2)
152 #define BZIP2_MEM_COMPRESS 0
153 #define BZIP2_MEM_DECOMPRESS 0
155 static
156 int bzip2_compress ( const m_bytep src, m_uint src_len,
157 m_bytep dst, m_uintp dst_len,
158 m_voidp wrkmem,
159 int compression_level )
161 int err;
162 unsigned destLen;
163 union { const m_bytep csrc; char *src; } u;
165 u.csrc = src; /* UNCONST */
166 destLen = *dst_len;
167 err = BZ2_bzBuffToBuffCompress((char*)dst, &destLen, u.src, src_len, compression_level, 0, 0);
168 *dst_len = destLen;
169 LZO_UNUSED(wrkmem);
170 return err;
174 M_PRIVATE(int)
175 bzip2_decompress ( const m_bytep src, m_uint src_len,
176 m_bytep dst, m_uintp dst_len,
177 m_voidp wrkmem )
179 int err;
180 unsigned destLen;
181 union { const m_bytep csrc; char *src; } u;
183 u.csrc = src; /* UNCONST */
184 destLen = *dst_len;
185 err = BZ2_bzBuffToBuffDecompress((char*)dst, &destLen, u.src, src_len, 0, 0);
186 *dst_len = destLen;
187 LZO_UNUSED(wrkmem);
188 return err;
192 M_PRIVATE(int)
193 bzip2_1_compress ( const m_bytep src, m_uint src_len,
194 m_bytep dst, m_uintp dst_len,
195 m_voidp wrkmem )
196 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,1); }
198 M_PRIVATE(int)
199 bzip2_2_compress ( const m_bytep src, m_uint src_len,
200 m_bytep dst, m_uintp dst_len,
201 m_voidp wrkmem )
202 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,2); }
204 M_PRIVATE(int)
205 bzip2_3_compress ( const m_bytep src, m_uint src_len,
206 m_bytep dst, m_uintp dst_len,
207 m_voidp wrkmem )
208 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,3); }
210 M_PRIVATE(int)
211 bzip2_4_compress ( const m_bytep src, m_uint src_len,
212 m_bytep dst, m_uintp dst_len,
213 m_voidp wrkmem )
214 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,4); }
216 M_PRIVATE(int)
217 bzip2_5_compress ( const m_bytep src, m_uint src_len,
218 m_bytep dst, m_uintp dst_len,
219 m_voidp wrkmem )
220 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,5); }
222 M_PRIVATE(int)
223 bzip2_6_compress ( const m_bytep src, m_uint src_len,
224 m_bytep dst, m_uintp dst_len,
225 m_voidp wrkmem )
226 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,6); }
228 M_PRIVATE(int)
229 bzip2_7_compress ( const m_bytep src, m_uint src_len,
230 m_bytep dst, m_uintp dst_len,
231 m_voidp wrkmem )
232 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,7); }
234 M_PRIVATE(int)
235 bzip2_8_compress ( const m_bytep src, m_uint src_len,
236 m_bytep dst, m_uintp dst_len,
237 m_voidp wrkmem )
238 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,8); }
240 M_PRIVATE(int)
241 bzip2_9_compress ( const m_bytep src, m_uint src_len,
242 m_bytep dst, m_uintp dst_len,
243 m_voidp wrkmem )
244 { return bzip2_compress(src,src_len,dst,dst_len,wrkmem,9); }
247 #endif /* ALG_BZIP2 */
250 /*************************************************************************
251 // other wrappers (for benchmarking the checksum algorithms)
252 **************************************************************************/
254 #if defined(ALG_ZLIB)
256 M_PRIVATE(int)
257 zlib_adler32_x_compress ( const m_bytep src, m_uint src_len,
258 m_bytep dst, m_uintp dst_len,
259 m_voidp wrkmem )
261 uLong adler;
262 adler = adler32(1L, src, (uInt) src_len);
263 *dst_len = src_len;
264 LZO_UNUSED(adler);
265 LZO_UNUSED(dst);
266 LZO_UNUSED(wrkmem);
267 return 0;
271 M_PRIVATE(int)
272 zlib_crc32_x_compress ( const m_bytep src, m_uint src_len,
273 m_bytep dst, m_uintp dst_len,
274 m_voidp wrkmem )
276 uLong crc;
277 crc = crc32(0L, src, (uInt) src_len);
278 *dst_len = src_len;
279 LZO_UNUSED(crc);
280 LZO_UNUSED(dst);
281 LZO_UNUSED(wrkmem);
282 return 0;
285 #endif /* ALG_ZLIB */
289 vi:ts=4:et