kusano 7d535a
/* lzo_util.c -- utilities for the LZO library
kusano 7d535a
kusano 7d535a
   This file is part of the LZO real-time data compression library.
kusano 7d535a
kusano 7d535a
   Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
kusano 7d535a
   All Rights Reserved.
kusano 7d535a
kusano 7d535a
   The LZO library is free software; you can redistribute it and/or
kusano 7d535a
   modify it under the terms of the GNU General Public License as
kusano 7d535a
   published by the Free Software Foundation; either version 2 of
kusano 7d535a
   the License, or (at your option) any later version.
kusano 7d535a
kusano 7d535a
   The LZO library is distributed in the hope that it will be useful,
kusano 7d535a
   but WITHOUT ANY WARRANTY; without even the implied warranty of
kusano 7d535a
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
kusano 7d535a
   GNU General Public License for more details.
kusano 7d535a
kusano 7d535a
   You should have received a copy of the GNU General Public License
kusano 7d535a
   along with the LZO library; see the file COPYING.
kusano 7d535a
   If not, write to the Free Software Foundation, Inc.,
kusano 7d535a
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
kusano 7d535a
kusano 7d535a
   Markus F.X.J. Oberhumer
kusano 7d535a
   <markus@oberhumer.com></markus@oberhumer.com>
kusano 7d535a
   http://www.oberhumer.com/opensource/lzo/
kusano 7d535a
 */
kusano 7d535a
kusano 7d535a
kusano 7d535a
#include "lzo_conf.h"
kusano 7d535a
kusano 7d535a
kusano 7d535a
/***********************************************************************
kusano 7d535a
//
kusano 7d535a
************************************************************************/
kusano 7d535a
kusano 7d535a
/* If you use the LZO library in a product, I would appreciate that you
kusano 7d535a
 * keep this copyright string in the executable of your product.
kusano 7d535a
.*/
kusano 7d535a
kusano 7d535a
const char __lzo_copyright[] =
kusano 7d535a
#if !defined(__LZO_IN_MINLZO)
kusano 7d535a
    /* save space as some people want a really small decompressor */
kusano 7d535a
    LZO_VERSION_STRING;
kusano 7d535a
#else
kusano 7d535a
    "\r\n\n"
kusano 7d535a
    "LZO data compression library.\n"
kusano 7d535a
    "$Copyright: LZO (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Markus Franz Xaver Johannes Oberhumer\n"
kusano 7d535a
    "<markus@oberhumer.com>\n"</markus@oberhumer.com>
kusano 7d535a
    "http://www.oberhumer.com $\n\n"
kusano 7d535a
    "$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n"
kusano 7d535a
    "$Built: " __DATE__ " " __TIME__ " $\n"
kusano 7d535a
    "$Info: " LZO_INFO_STRING " $\n";
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
LZO_PUBLIC(const lzo_bytep)
kusano 7d535a
lzo_copyright(void)
kusano 7d535a
{
kusano 7d535a
#if (LZO_OS_DOS16 && LZO_CC_TURBOC)
kusano 7d535a
    return (lzo_voidp) __lzo_copyright;
kusano 7d535a
#else
kusano 7d535a
    return (const lzo_bytep) __lzo_copyright;
kusano 7d535a
#endif
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
LZO_PUBLIC(unsigned)
kusano 7d535a
lzo_version(void)
kusano 7d535a
{
kusano 7d535a
    return LZO_VERSION;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
LZO_PUBLIC(const char *)
kusano 7d535a
lzo_version_string(void)
kusano 7d535a
{
kusano 7d535a
    return LZO_VERSION_STRING;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
LZO_PUBLIC(const char *)
kusano 7d535a
lzo_version_date(void)
kusano 7d535a
{
kusano 7d535a
    return LZO_VERSION_DATE;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
LZO_PUBLIC(const lzo_charp)
kusano 7d535a
_lzo_version_string(void)
kusano 7d535a
{
kusano 7d535a
    return LZO_VERSION_STRING;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
LZO_PUBLIC(const lzo_charp)
kusano 7d535a
_lzo_version_date(void)
kusano 7d535a
{
kusano 7d535a
    return LZO_VERSION_DATE;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/***********************************************************************
kusano 7d535a
// adler32 checksum
kusano 7d535a
// adapted from free code by Mark Adler <madler@alumni.caltech.edu></madler@alumni.caltech.edu>
kusano 7d535a
// see http://www.zlib.org/
kusano 7d535a
************************************************************************/
kusano 7d535a
kusano 7d535a
#define LZO_BASE 65521u /* largest prime smaller than 65536 */
kusano 7d535a
#define LZO_NMAX 5552
kusano 7d535a
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
kusano 7d535a
kusano 7d535a
#define LZO_DO1(buf,i)  s1 += buf[i]; s2 += s1
kusano 7d535a
#define LZO_DO2(buf,i)  LZO_DO1(buf,i); LZO_DO1(buf,i+1);
kusano 7d535a
#define LZO_DO4(buf,i)  LZO_DO2(buf,i); LZO_DO2(buf,i+2);
kusano 7d535a
#define LZO_DO8(buf,i)  LZO_DO4(buf,i); LZO_DO4(buf,i+4);
kusano 7d535a
#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8);
kusano 7d535a
kusano 7d535a
LZO_PUBLIC(lzo_uint32)
kusano 7d535a
lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len)
kusano 7d535a
{
kusano 7d535a
    lzo_uint32 s1 = adler & 0xffff;
kusano 7d535a
    lzo_uint32 s2 = (adler >> 16) & 0xffff;
kusano 7d535a
    unsigned k;
kusano 7d535a
kusano 7d535a
    if (buf == NULL)
kusano 7d535a
        return 1;
kusano 7d535a
kusano 7d535a
    while (len > 0)
kusano 7d535a
    {
kusano 7d535a
        k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX;
kusano 7d535a
        len -= k;
kusano 7d535a
        if (k >= 16) do
kusano 7d535a
        {
kusano 7d535a
            LZO_DO16(buf,0);
kusano 7d535a
            buf += 16;
kusano 7d535a
            k -= 16;
kusano 7d535a
        } while (k >= 16);
kusano 7d535a
        if (k != 0) do
kusano 7d535a
        {
kusano 7d535a
            s1 += *buf++;
kusano 7d535a
            s2 += s1;
kusano 7d535a
        } while (--k > 0);
kusano 7d535a
        s1 %= LZO_BASE;
kusano 7d535a
        s2 %= LZO_BASE;
kusano 7d535a
    }
kusano 7d535a
    return (s2 << 16) | s1;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
#undef LZO_DO1
kusano 7d535a
#undef LZO_DO2
kusano 7d535a
#undef LZO_DO4
kusano 7d535a
#undef LZO_DO8
kusano 7d535a
#undef LZO_DO16
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
vi:ts=4:et
kusano 7d535a
*/