[阅读: 590] 2005-11-25 09:24:45
/* ========================================================================= */
#define DO1(buf) crc = crc_table[((unsigned long)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);
/* ========================================================================= */
unsigned long crc32(unsigned long crc, const char * buf, int len)
{
if (buf == NULL)
{
return 0L;
}
crc = crc ^ 0xffffffffL;
while (len >= 8)
{
DO8(buf);
len -= 8;
}
if (len) do {
DO1(buf);
} while (--len);
return crc ^ 0xffffffffL;
}