Blame lzotest/wrapmisc.h

Packit Service 5195f2
/* wrapmisc.h -- misc wrapper functions for the test driver
Packit Service 5195f2
Packit Service 5195f2
   This file is part of the LZO real-time data compression library.
Packit Service 5195f2
Packit Service 5195f2
   Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer
Packit Service 5195f2
   All Rights Reserved.
Packit Service 5195f2
Packit Service 5195f2
   The LZO library is free software; you can redistribute it and/or
Packit Service 5195f2
   modify it under the terms of the GNU General Public License as
Packit Service 5195f2
   published by the Free Software Foundation; either version 2 of
Packit Service 5195f2
   the License, or (at your option) any later version.
Packit Service 5195f2
Packit Service 5195f2
   The LZO library is distributed in the hope that it will be useful,
Packit Service 5195f2
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 5195f2
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 5195f2
   GNU General Public License for more details.
Packit Service 5195f2
Packit Service 5195f2
   You should have received a copy of the GNU General Public License
Packit Service 5195f2
   along with the LZO library; see the file COPYING.
Packit Service 5195f2
   If not, write to the Free Software Foundation, Inc.,
Packit Service 5195f2
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit Service 5195f2
Packit Service 5195f2
   Markus F.X.J. Oberhumer
Packit Service 5195f2
   <markus@oberhumer.com>
Packit Service 5195f2
   http://www.oberhumer.com/opensource/lzo/
Packit Service 5195f2
 */
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
/*************************************************************************
Packit Service 5195f2
// compression levels of zlib
Packit Service 5195f2
**************************************************************************/
Packit Service 5195f2
Packit Service 5195f2
#if defined(ALG_ZLIB)
Packit Service 5195f2
Packit Service 5195f2
#define ZLIB_MEM_COMPRESS       0
Packit Service 5195f2
#define ZLIB_MEM_DECOMPRESS     0
Packit Service 5195f2
Packit Service 5195f2
static
Packit Service 5195f2
int zlib_compress       ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem,
Packit Service 5195f2
                                int method, int compression_level )
Packit Service 5195f2
{
Packit Service 5195f2
    int err;
Packit Service 5195f2
    uLong destLen;
Packit Service 5195f2
Packit Service 5195f2
    assert(method == Z_DEFLATED);
Packit Service 5195f2
    destLen = (uLong) *dst_len;
Packit Service 5195f2
    err = compress2(dst, &destLen, src, (uLong) src_len, compression_level);
Packit Service 5195f2
    *dst_len = destLen;
Packit Service 5195f2
    LZO_UNUSED(method);
Packit Service 5195f2
    LZO_UNUSED(wrkmem);
Packit Service 5195f2
    return err;
Packit Service 5195f2
}
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
zlib_decompress         ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{
Packit Service 5195f2
    int err;
Packit Service 5195f2
    uLong destLen;
Packit Service 5195f2
Packit Service 5195f2
    destLen = (uLong) *dst_len;
Packit Service 5195f2
    err = uncompress(dst, &destLen, src, (uLong) src_len);
Packit Service 5195f2
    *dst_len = destLen;
Packit Service 5195f2
    LZO_UNUSED(wrkmem);
Packit Service 5195f2
    return err;
Packit Service 5195f2
}
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
zlib_8_1_compress       ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,1); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
zlib_8_2_compress       ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,2); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
zlib_8_3_compress       ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,3); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
zlib_8_4_compress       ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,4); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
zlib_8_5_compress       ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,5); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
zlib_8_6_compress       ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,6); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
zlib_8_7_compress       ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,7); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
zlib_8_8_compress       ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,8); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
zlib_8_9_compress       ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return zlib_compress(src,src_len,dst,dst_len,wrkmem,Z_DEFLATED,9); }
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
#endif /* ALG_ZLIB */
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
/*************************************************************************
Packit Service 5195f2
// compression levels of bzip2
Packit Service 5195f2
**************************************************************************/
Packit Service 5195f2
Packit Service 5195f2
#if defined(ALG_BZIP2)
Packit Service 5195f2
Packit Service 5195f2
#define BZIP2_MEM_COMPRESS      0
Packit Service 5195f2
#define BZIP2_MEM_DECOMPRESS    0
Packit Service 5195f2
Packit Service 5195f2
static
Packit Service 5195f2
int bzip2_compress      ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem,
Packit Service 5195f2
                                int compression_level )
Packit Service 5195f2
{
Packit Service 5195f2
    int err;
Packit Service 5195f2
    unsigned destLen;
Packit Service 5195f2
    union { const m_bytep csrc; char *src; } u;
Packit Service 5195f2
Packit Service 5195f2
    u.csrc = src; /* UNCONST */
Packit Service 5195f2
    destLen = *dst_len;
Packit Service 5195f2
    err = BZ2_bzBuffToBuffCompress((char*)dst, &destLen, u.src, src_len, compression_level, 0, 0);
Packit Service 5195f2
    *dst_len = destLen;
Packit Service 5195f2
    LZO_UNUSED(wrkmem);
Packit Service 5195f2
    return err;
Packit Service 5195f2
}
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
bzip2_decompress        ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{
Packit Service 5195f2
    int err;
Packit Service 5195f2
    unsigned destLen;
Packit Service 5195f2
    union { const m_bytep csrc; char *src; } u;
Packit Service 5195f2
Packit Service 5195f2
    u.csrc = src; /* UNCONST */
Packit Service 5195f2
    destLen = *dst_len;
Packit Service 5195f2
    err = BZ2_bzBuffToBuffDecompress((char*)dst, &destLen, u.src, src_len, 0, 0);
Packit Service 5195f2
    *dst_len = destLen;
Packit Service 5195f2
    LZO_UNUSED(wrkmem);
Packit Service 5195f2
    return err;
Packit Service 5195f2
}
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
bzip2_1_compress        ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,1); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
bzip2_2_compress        ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,2); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
bzip2_3_compress        ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,3); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
bzip2_4_compress        ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,4); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
bzip2_5_compress        ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,5); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
bzip2_6_compress        ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,6); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
bzip2_7_compress        ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,7); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
bzip2_8_compress        ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,8); }
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
bzip2_9_compress        ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{ return bzip2_compress(src,src_len,dst,dst_len,wrkmem,9); }
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
#endif /* ALG_BZIP2 */
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
/*************************************************************************
Packit Service 5195f2
// other wrappers (for benchmarking the checksum algorithms)
Packit Service 5195f2
**************************************************************************/
Packit Service 5195f2
Packit Service 5195f2
#if defined(ALG_ZLIB)
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
zlib_adler32_x_compress ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{
Packit Service 5195f2
    uLong adler;
Packit Service 5195f2
    adler = adler32(1L, src, (uInt) src_len);
Packit Service 5195f2
    *dst_len = src_len;
Packit Service 5195f2
    LZO_UNUSED(adler);
Packit Service 5195f2
    LZO_UNUSED(dst);
Packit Service 5195f2
    LZO_UNUSED(wrkmem);
Packit Service 5195f2
    return 0;
Packit Service 5195f2
}
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
M_PRIVATE(int)
Packit Service 5195f2
zlib_crc32_x_compress   ( const m_bytep src, m_uint  src_len,
Packit Service 5195f2
                                m_bytep dst, m_uintp dst_len,
Packit Service 5195f2
                                m_voidp wrkmem )
Packit Service 5195f2
{
Packit Service 5195f2
    uLong crc;
Packit Service 5195f2
    crc = crc32(0L, src, (uInt) src_len);
Packit Service 5195f2
    *dst_len = src_len;
Packit Service 5195f2
    LZO_UNUSED(crc);
Packit Service 5195f2
    LZO_UNUSED(dst);
Packit Service 5195f2
    LZO_UNUSED(wrkmem);
Packit Service 5195f2
    return 0;
Packit Service 5195f2
}
Packit Service 5195f2
Packit Service 5195f2
#endif /* ALG_ZLIB */
Packit Service 5195f2
Packit Service 5195f2
Packit Service 5195f2
/* vim:set ts=4 sw=4 et: */