mirror of
https://github.com/depp/syncfiles.git
synced 2024-11-22 03:30:57 +00:00
41 lines
563 B
C
41 lines
563 B
C
#include "lib/crc32.h"
|
|
|
|
static int gCRCInitted;
|
|
static UInt32 gCRCTable[256];
|
|
|
|
static void CRC32Init(void)
|
|
{
|
|
int i, j;
|
|
UInt32 v, u;
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
v = i;
|
|
for (j = 0; j < 8; j++) {
|
|
u = v;
|
|
v >>= 1;
|
|
if (u & 1) {
|
|
v ^= 0xedb88320;
|
|
}
|
|
}
|
|
gCRCTable[i] = v;
|
|
}
|
|
gCRCInitted = 1;
|
|
}
|
|
|
|
UInt32 CRC32Update(UInt32 crc, const void *ptr, Size size)
|
|
{
|
|
const UInt8 *p, *e;
|
|
|
|
if (!gCRCInitted) {
|
|
CRC32Init();
|
|
}
|
|
|
|
crc = ~crc;
|
|
p = ptr;
|
|
e = p + size;
|
|
while (p < e) {
|
|
crc = (crc >> 8) ^ gCRCTable[(crc & 0xff) ^ *p++];
|
|
}
|
|
return ~crc;
|
|
}
|