/[LeafOK_CVS]/pvpgn-1.7.4/src/zlib/pvpgn_adler32.c
ViewVC logotype

Annotation of /pvpgn-1.7.4/src/zlib/pvpgn_adler32.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Tue Jun 6 03:41:38 2006 UTC (19 years, 9 months ago) by sysadm
CVS Tags: pvpgn_1-7-4-0_MIL
Branch point for: GNU, MAIN
Content type: text/x-csrc
Initial revision

1 sysadm 1.1 /* adler32.c -- compute the Adler-32 checksum of a data stream
2     * Copyright (C) 1995-2002 Mark Adler
3     * For conditions of distribution and use, see copyright notice in zlib.h
4     */
5    
6     #include "common/setup_before.h"
7     #include "zlib/pvpgn_zlib.h"
8    
9     #define BASE 65521L /* largest prime smaller than 65536 */
10     #define NMAX 5552
11     /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
12    
13     #define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
14     #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
15     #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
16     #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
17     #define DO16(buf) DO8(buf,0); DO8(buf,8);
18    
19     /* ========================================================================= */
20     uLong ZEXPORT pvpgn_adler32(adler, buf, len)
21     uLong adler;
22     const Bytef *buf;
23     uInt len;
24     {
25     unsigned long s1 = adler & 0xffff;
26     unsigned long s2 = (adler >> 16) & 0xffff;
27     int k;
28    
29     if (buf == Z_NULL) return 1L;
30    
31     while (len > 0) {
32     k = len < NMAX ? len : NMAX;
33     len -= k;
34     while (k >= 16) {
35     DO16(buf);
36     buf += 16;
37     k -= 16;
38     }
39     if (k != 0) do {
40     s1 += *buf++;
41     s2 += s1;
42     } while (--k);
43     s1 %= BASE;
44     s2 %= BASE;
45     }
46     return (s2 << 16) | s1;
47     }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1