1 | /* lzo_util.c -- utilities for the LZO library |
---|
2 | |
---|
3 | This file is part of the LZO real-time data compression library. |
---|
4 | |
---|
5 | Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer |
---|
6 | All Rights Reserved. |
---|
7 | |
---|
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. |
---|
12 | |
---|
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. |
---|
17 | |
---|
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. |
---|
22 | |
---|
23 | Markus F.X.J. Oberhumer |
---|
24 | <markus@oberhumer.com> |
---|
25 | http://www.oberhumer.com/opensource/lzo/ |
---|
26 | */ |
---|
27 | |
---|
28 | |
---|
29 | #include "lzo_conf.h" |
---|
30 | |
---|
31 | |
---|
32 | /*********************************************************************** |
---|
33 | // |
---|
34 | ************************************************************************/ |
---|
35 | |
---|
36 | /* If you use the LZO library in a product, I would appreciate that you |
---|
37 | * keep this copyright string in the executable of your product. |
---|
38 | .*/ |
---|
39 | |
---|
40 | static const char __lzo_copyright[] = |
---|
41 | #if !defined(__LZO_IN_MINLZO) |
---|
42 | /* save space as some people want a really small decompressor */ |
---|
43 | LZO_VERSION_STRING; |
---|
44 | #else |
---|
45 | "\r\n\n" |
---|
46 | "LZO data compression library.\n" |
---|
47 | "$Copyright: LZO Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer\n" |
---|
48 | "<markus@oberhumer.com>\n" |
---|
49 | "http://www.oberhumer.com $\n\n" |
---|
50 | "$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n" |
---|
51 | "$Info: " LZO_INFO_STRING " $\n"; |
---|
52 | #endif |
---|
53 | |
---|
54 | |
---|
55 | LZO_PUBLIC(const lzo_bytep) |
---|
56 | lzo_copyright(void) |
---|
57 | { |
---|
58 | return (const lzo_bytep) __lzo_copyright; |
---|
59 | } |
---|
60 | |
---|
61 | LZO_PUBLIC(unsigned) |
---|
62 | lzo_version(void) |
---|
63 | { |
---|
64 | return LZO_VERSION; |
---|
65 | } |
---|
66 | |
---|
67 | LZO_PUBLIC(const char *) |
---|
68 | lzo_version_string(void) |
---|
69 | { |
---|
70 | return LZO_VERSION_STRING; |
---|
71 | } |
---|
72 | |
---|
73 | LZO_PUBLIC(const char *) |
---|
74 | lzo_version_date(void) |
---|
75 | { |
---|
76 | return LZO_VERSION_DATE; |
---|
77 | } |
---|
78 | |
---|
79 | LZO_PUBLIC(const lzo_charp) |
---|
80 | _lzo_version_string(void) |
---|
81 | { |
---|
82 | return LZO_VERSION_STRING; |
---|
83 | } |
---|
84 | |
---|
85 | LZO_PUBLIC(const lzo_charp) |
---|
86 | _lzo_version_date(void) |
---|
87 | { |
---|
88 | return LZO_VERSION_DATE; |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | /*********************************************************************** |
---|
93 | // adler32 checksum |
---|
94 | // adapted from free code by Mark Adler <madler@alumni.caltech.edu> |
---|
95 | // see http://www.zlib.org/ |
---|
96 | ************************************************************************/ |
---|
97 | |
---|
98 | #define LZO_BASE 65521u /* largest prime smaller than 65536 */ |
---|
99 | #define LZO_NMAX 5552 |
---|
100 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ |
---|
101 | |
---|
102 | #define LZO_DO1(buf,i) s1 += buf[i]; s2 += s1 |
---|
103 | #define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1); |
---|
104 | #define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2); |
---|
105 | #define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4); |
---|
106 | #define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8); |
---|
107 | |
---|
108 | LZO_PUBLIC(lzo_uint32_t) |
---|
109 | lzo_adler32(lzo_uint32_t adler, const lzo_bytep buf, lzo_uint len) |
---|
110 | { |
---|
111 | lzo_uint32_t s1 = adler & 0xffff; |
---|
112 | lzo_uint32_t s2 = (adler >> 16) & 0xffff; |
---|
113 | unsigned k; |
---|
114 | |
---|
115 | if (buf == NULL) |
---|
116 | return 1; |
---|
117 | |
---|
118 | while (len > 0) |
---|
119 | { |
---|
120 | k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX; |
---|
121 | len -= k; |
---|
122 | if (k >= 16) do |
---|
123 | { |
---|
124 | LZO_DO16(buf,0); |
---|
125 | buf += 16; |
---|
126 | k -= 16; |
---|
127 | } while (k >= 16); |
---|
128 | if (k != 0) do |
---|
129 | { |
---|
130 | s1 += *buf++; |
---|
131 | s2 += s1; |
---|
132 | } while (--k > 0); |
---|
133 | s1 %= LZO_BASE; |
---|
134 | s2 %= LZO_BASE; |
---|
135 | } |
---|
136 | return (s2 << 16) | s1; |
---|
137 | } |
---|
138 | |
---|
139 | #undef LZO_DO1 |
---|
140 | #undef LZO_DO2 |
---|
141 | #undef LZO_DO4 |
---|
142 | #undef LZO_DO8 |
---|
143 | #undef LZO_DO16 |
---|
144 | |
---|
145 | |
---|
146 | /* |
---|
147 | vi:ts=4:et |
---|
148 | */ |
---|