os/ossrv/compressionlibs/ziplib/test/oldezlib/EZLib/adler32.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/compressionlibs/ziplib/test/oldezlib/EZLib/adler32.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,48 @@
     1.4 +/* adler32.c -- compute the Adler-32 checksum of a data stream
     1.5 + * Copyright (C) 1995-1998 Mark Adler
     1.6 + * For conditions of distribution and use, see copyright notice in zlib.h 
     1.7 + */
     1.8 +
     1.9 +/* @(#) $Id$ */
    1.10 +
    1.11 +#include "OldEZlib.h"
    1.12 +
    1.13 +#define BASE 65521L /* largest prime smaller than 65536 */
    1.14 +#define NMAX 5552
    1.15 +/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
    1.16 +
    1.17 +#define DO1(buf,i)  {s1 += buf[i]; s2 += s1;}
    1.18 +#define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
    1.19 +#define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
    1.20 +#define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
    1.21 +#define DO16(buf)   DO8(buf,0); DO8(buf,8);
    1.22 +
    1.23 +/* ========================================================================= */
    1.24 +EXPORT_C uLong ZEXPORT adler32(
    1.25 +    uLong adler,
    1.26 +    const Bytef *buf,
    1.27 +    uInt len)
    1.28 +{
    1.29 +    unsigned long s1 = adler & 0xffff;
    1.30 +    unsigned long s2 = (adler >> 16) & 0xffff;
    1.31 +    int k;
    1.32 +
    1.33 +    if (buf == Z_NULL) return 1L;
    1.34 +
    1.35 +    while (len > 0) {
    1.36 +        k = len < NMAX ? len : NMAX;
    1.37 +        len -= k;
    1.38 +        while (k >= 16) {
    1.39 +            DO16(buf);
    1.40 +	    buf += 16;
    1.41 +            k -= 16;
    1.42 +        }
    1.43 +        if (k != 0) do {
    1.44 +            s1 += *buf++;
    1.45 +	    s2 += s1;
    1.46 +        } while (--k);
    1.47 +        s1 %= BASE;
    1.48 +        s2 %= BASE;
    1.49 +    }
    1.50 +    return (s2 << 16) | s1;
    1.51 +}