1 /* lzo_util.c -- utilities for the LZO library
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
6 Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
7 Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
8 Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
9 Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
10 Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
11 Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
12 Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
13 Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
14 Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
15 Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
16 Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
17 Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
20 The LZO library is free software; you can redistribute it and/or
21 modify it under the terms of the GNU General Public License as
22 published by the Free Software Foundation; either version 2 of
23 the License, or (at your option) any later version.
25 The LZO library is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
30 You should have received a copy of the GNU General Public License
31 along with the LZO library; see the file COPYING.
32 If not, write to the Free Software Foundation, Inc.,
33 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
35 Markus F.X.J. Oberhumer
36 <markus@oberhumer.com>
37 http://www.oberhumer.com/opensource/lzo/
44 /***********************************************************************
46 ************************************************************************/
48 /* If you use the LZO library in a product, I would appreciate that you
49 * keep this copyright string in the executable of your product.
52 const char __lzo_copyright
[] =
53 #if !defined(__LZO_IN_MINLZO)
54 /* save space as some people want a really small decompressor */
58 "LZO data compression library.\n"
59 "$Copyright: LZO (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Markus Franz Xaver Johannes Oberhumer\n"
60 "<markus@oberhumer.com>\n"
61 "http://www.oberhumer.com $\n\n"
62 "$Id: LZO version: v" LZO_VERSION_STRING
", " LZO_VERSION_DATE
" $\n"
63 "$Built: " __DATE__
" " __TIME__
" $\n"
64 "$Info: " LZO_INFO_STRING
" $\n";
68 LZO_PUBLIC(const lzo_bytep
)
71 #if (LZO_OS_DOS16 && LZO_CC_TURBOC)
72 return (lzo_voidp
) __lzo_copyright
;
74 return (const lzo_bytep
) __lzo_copyright
;
84 LZO_PUBLIC(const char *)
85 lzo_version_string(void)
87 return LZO_VERSION_STRING
;
90 LZO_PUBLIC(const char *)
91 lzo_version_date(void)
93 return LZO_VERSION_DATE
;
96 LZO_PUBLIC(const lzo_charp
)
97 _lzo_version_string(void)
99 return LZO_VERSION_STRING
;
102 LZO_PUBLIC(const lzo_charp
)
103 _lzo_version_date(void)
105 return LZO_VERSION_DATE
;
109 /***********************************************************************
111 // adapted from free code by Mark Adler <madler@alumni.caltech.edu>
112 // see http://www.zlib.org/
113 ************************************************************************/
115 #define LZO_BASE 65521u /* largest prime smaller than 65536 */
116 #define LZO_NMAX 5552
117 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
119 #define LZO_DO1(buf,i) s1 += buf[i]; s2 += s1
120 #define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1);
121 #define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2);
122 #define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4);
123 #define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8);
125 LZO_PUBLIC(lzo_uint32
)
126 lzo_adler32(lzo_uint32 adler
, const lzo_bytep buf
, lzo_uint len
)
128 lzo_uint32 s1
= adler
& 0xffff;
129 lzo_uint32 s2
= (adler
>> 16) & 0xffff;
137 k
= len
< LZO_NMAX
? (unsigned) len
: LZO_NMAX
;
153 return (s2
<< 16) | s1
;