2 Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
4 See the accompanying file LICENSE, version 2000-Apr-09 or later
5 (the contents of which are also included in zip.h) for terms of use.
6 If, for some reason, all these files are missing, the Info-ZIP license
7 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
9 /* crc32.c -- compute the CRC-32 of a data stream
10 * Copyright (C) 1995 Mark Adler
11 * For conditions of distribution and use, see copyright notice in zlib.h
14 /* $Id: crc32.c 1101 2002-09-21 14:54:45Z darkwyrm $ */
16 #define __CRC32_C /* identifies this source module */
30 #define CRC32(c, b) (crc_table[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8))
31 #define DO1(buf) crc = CRC32(crc, *buf++)
32 #define DO2(buf) DO1(buf); DO1(buf)
33 #define DO4(buf) DO2(buf); DO2(buf)
34 #define DO8(buf) DO4(buf); DO4(buf)
36 /* ========================================================================= */
37 ulg
crc32(crc
, buf
, len
)
38 register ulg crc
; /* crc shift register */
39 register ZCONST uch
*buf
; /* pointer to bytes to pump through */
40 extent len
; /* number of bytes in buf[] */
41 /* Run a set of bytes through the crc shift register. If buf is a NULL
42 pointer, then initialize the crc shift register contents instead.
43 Return the current crc in either case. */
45 register ZCONST ulg near
*crc_table
;
47 if (buf
== NULL
) return 0L;
49 crc_table
= get_crc_table();
51 crc
= crc
^ 0xffffffffL
;
52 #ifndef NO_UNROLLED_LOOPS
61 return crc
^ 0xffffffffL
; /* (instead of ~c for 64-bit machines) */
64 #endif /* !USE_ZLIB */