]> git.saurik.com Git - wxWidgets.git/blob - utils/Install/packzip/crc32.c
don't log mouse events by default
[wxWidgets.git] / utils / Install / packzip / crc32.c
1 /* crc32.c -- compute the CRC-32 of a data stream
2 * Copyright (C) 1995 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6 /* $Id$ */
7
8 #define __CRC32_C /* identifies this source module */
9
10 #include "zip.h"
11
12 #ifndef USE_ZLIB
13 #ifndef ASM_CRC
14
15 #ifndef ZCONST
16 # define ZCONST const
17 #endif
18
19 #ifdef CRC32
20 # undef CRC32
21 #endif
22 #define CRC32(c, b) (crc_table[((int)(c) ^ (b)) & 0xff] ^ ((c) >> 8))
23 #define DO1(buf) crc = CRC32(crc, *buf++)
24 #define DO2(buf) DO1(buf); DO1(buf)
25 #define DO4(buf) DO2(buf); DO2(buf)
26 #define DO8(buf) DO4(buf); DO4(buf)
27
28 /* ========================================================================= */
29 ulg crc32(crc, buf, len)
30 register ulg crc; /* crc shift register */
31 register ZCONST uch *buf; /* pointer to bytes to pump through */
32 extent len; /* number of bytes in buf[] */
33 /* Run a set of bytes through the crc shift register. If buf is a NULL
34 pointer, then initialize the crc shift register contents instead.
35 Return the current crc in either case. */
36 {
37 register ZCONST ulg near *crc_table;
38
39 if (buf == NULL) return 0L;
40
41 crc_table = get_crc_table();
42
43 crc = crc ^ 0xffffffffL;
44 #ifndef NO_UNROLLED_LOOPS
45 while (len >= 8) {
46 DO8(buf);
47 len -= 8;
48 }
49 #endif
50 if (len) do {
51 DO1(buf);
52 } while (--len);
53 return crc ^ 0xffffffffL; /* (instead of ~c for 64-bit machines) */
54 }
55 #endif /* !ASM_CRC */
56 #endif /* !USE_ZLIB */