summaryrefslogtreecommitdiffstats
path: root/main/zlib/zcrc32.c
blob: 2b3a18522eef8b2cd05e9c999489e1b7ede09c1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* crc32.c -- compute the CRC-32 of a data stream
 * Copyright (C) 1995-1998 Mark Adler
 * For conditions of distribution and use, see copyright notice in zlib.h
 */

#include "zlib.h"

#define local static
extern unsigned long crc32tab[];

#define DO1(buf) crc = crc32tab[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
#define DO2(buf)  DO1(buf); DO1(buf);
#define DO4(buf)  DO2(buf); DO2(buf);
#define DO8(buf)  DO4(buf); DO4(buf);

/* ========================================================================= */
uLong ZEXPORT zcrc32(crc, buf, len)
uLong crc;
const Bytef *buf;
uInt len;
{
    if(buf == Z_NULL) {
        return 0L;
    }
    crc = crc ^ 0xffffffffL;
    while(len >= 8) {
        DO8(buf);
        len -= 8;
    }
    if(len) do {
            DO1(buf);
        } while(--len);
    return crc ^ 0xffffffffL;
}