diff options
Diffstat (limited to 'crc32.c')
-rw-r--r-- | crc32.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -3,12 +3,17 @@ | |||
3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
4 | */ | 4 | */ |
5 | 5 | ||
6 | /* $Id: crc32.c,v 1.4 1995/04/14 14:55:12 jloup Exp $ */ | 6 | /* $Id: crc32.c,v 1.5 1995/05/01 13:55:46 jloup Exp $ */ |
7 | 7 | ||
8 | #include "zlib.h" | 8 | #include "zlib.h" |
9 | 9 | ||
10 | extern uLong crc_table[]; /* crc table, defined below */ | 10 | extern uLong crc_table[]; /* crc table, defined below */ |
11 | 11 | ||
12 | #define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); | ||
13 | #define DO2(buf) DO1(buf); DO1(buf); | ||
14 | #define DO4(buf) DO2(buf); DO2(buf); | ||
15 | #define DO8(buf) DO4(buf); DO4(buf); | ||
16 | |||
12 | /* ========================================================================= */ | 17 | /* ========================================================================= */ |
13 | uLong crc32(crc, buf, len) | 18 | uLong crc32(crc, buf, len) |
14 | uLong crc; | 19 | uLong crc; |
@@ -17,8 +22,13 @@ uLong crc32(crc, buf, len) | |||
17 | { | 22 | { |
18 | if (buf == Z_NULL) return 0L; | 23 | if (buf == Z_NULL) return 0L; |
19 | crc = crc ^ 0xffffffffL; | 24 | crc = crc ^ 0xffffffffL; |
25 | while (len >= 8) | ||
26 | { | ||
27 | DO8(buf); | ||
28 | len -= 8; | ||
29 | } | ||
20 | if (len) do { | 30 | if (len) do { |
21 | crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); | 31 | DO1(buf); |
22 | } while (--len); | 32 | } while (--len); |
23 | return crc ^ 0xffffffffL; | 33 | return crc ^ 0xffffffffL; |
24 | } | 34 | } |
@@ -29,7 +39,7 @@ uLong crc32(crc, buf, len) | |||
29 | */ | 39 | */ |
30 | #ifdef DYNAMIC_CRC_TABLE | 40 | #ifdef DYNAMIC_CRC_TABLE |
31 | 41 | ||
32 | void make_crc_table() | 42 | local void make_crc_table() |
33 | { | 43 | { |
34 | uLong c; | 44 | uLong c; |
35 | int n, k; | 45 | int n, k; |