2 * Original code from zlib: only stylistic changes have been made to the it.
3 * The following copyright notice has been kept as desired by the authors.
5 /* zlib.h -- interface of the 'zlib' general purpose compression library
7 Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
9 This software is provided 'as-is', without any express or implied
10 warranty. In no event will the authors be held liable for any damages
11 arising from the use of this software.
13 Permission is granted to anyone to use this software for any purpose,
14 including commercial applications, and to alter it and redistribute it
15 freely, subject to the following restrictions:
17 1. The origin of this software must not be misrepresented; you must not
18 claim that you wrote the original software. If you use this software
19 in a product, an acknowledgment in the product documentation would be
20 appreciated but is not required.
21 2. Altered source versions must be plainly marked as such, and must not be
22 misrepresented as being the original software.
23 3. This notice may not be removed or altered from any source distribution.
25 Jean-loup Gailly Mark Adler
26 jloup@gzip.org madler@alumni.caltech.edu
29 The data format used by the zlib library is described by RFCs (Request for
30 Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
31 (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
38 #define BASE 65521L /* largest prime smaller than 65536 */
39 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
42 #define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
43 #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
44 #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
45 #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
46 #define DO16(buf) DO8(buf,0); DO8(buf,8);
49 * Update a running Adler-32 checksum with the bytes buf[0..len-1] and
50 * return the updated checksum. If buf is NULL, this function returns
51 * the required initial value for the checksum.
52 * An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
53 * much faster. Usage example:
55 * unsigned long adler = adler32(0L, NULL, 0);
57 * while (read_buffer(buffer, length) != EOF) {
58 * adler = adler32(adler, buffer, length);
60 * if (adler != original_adler) error();
62 static inline unsigned long zlib_adler32(unsigned long adler
,
63 const unsigned char *buf
,
66 unsigned long s1
= adler
& 0xffff;
67 unsigned long s2
= (adler
>> 16) & 0xffff;
74 k
= len
< NMAX
? len
: NMAX
;
88 return (s2
<< 16) | s1
;
91 #endif /*__ADLER32_H__ */