aboutsummaryrefslogtreecommitdiff
path: root/crc32.c
diff options
context:
space:
mode:
Diffstat (limited to 'crc32.c')
-rw-r--r--crc32.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/crc32.c b/crc32.c
index d0a9f5e..f163fe1 100644
--- a/crc32.c
+++ b/crc32.c
@@ -18,25 +18,29 @@
18# endif /* !DYNAMIC_CRC_TABLE */ 18# endif /* !DYNAMIC_CRC_TABLE */
19#endif /* MAKECRCH */ 19#endif /* MAKECRCH */
20 20
21#include "zlib.h" 21#include "zutil.h"
22 22
23#define local static 23#define local static
24 24
25/* Find a four-byte integer type for crc32_little() and crc32_big(). */ 25/* Find a four-byte integer type for crc32_little() and crc32_big(). */
26#ifndef NOBYFOUR 26#ifndef NOBYFOUR
27# ifdef __STDC__ /* need ANSI C limits.h to determine sizes */ 27# ifdef STDC /* need ANSI C limits.h to determine sizes */
28# include <limits.h> 28# include <limits.h>
29# define BYFOUR 29# define BYFOUR
30# if (UINT_MAX == 4294967295) 30# if (UINT_MAX == 0xffffffffUL)
31 typedef unsigned int u4; 31 typedef unsigned int u4;
32# elif (ULONG_MAX == 4294967295)
33 typedef unsigned long u4;
34# elif (USHRT_MAX == 4294967295)
35 typedef unsigned short u4;
36# else 32# else
37# undef BYFOUR /* can't find a four-byte integer type! */ 33# if (ULONG_MAX == 0xffffffffUL)
34 typedef unsigned long u4;
35# else
36# if (USHRT_MAX == 0xffffffffUL)
37 typedef unsigned short u4;
38# else
39# undef BYFOUR /* can't find a four-byte integer type! */
40# endif
41# endif
38# endif 42# endif
39# endif /* __STDC__ */ 43# endif /* STDC */
40#endif /* !NOBYFOUR */ 44#endif /* !NOBYFOUR */
41 45
42/* Definitions for doing the crc four data bytes at a time. */ 46/* Definitions for doing the crc four data bytes at a time. */
@@ -95,7 +99,7 @@ local void make_crc_table()
95 /* terms of polynomial defining this crc (except x^32): */ 99 /* terms of polynomial defining this crc (except x^32): */
96 static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; 100 static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
97 101
98 /* make exclusive-or pattern from polynomial (0xedb88320L) */ 102 /* make exclusive-or pattern from polynomial (0xedb88320UL) */
99 poly = 0UL; 103 poly = 0UL;
100 for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++) 104 for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
101 poly |= 1UL << (31 - p[n]); 105 poly |= 1UL << (31 - p[n]);
@@ -240,7 +244,7 @@ local unsigned long crc32_little(crc, buf, len)
240 244
241 c = (u4)crc; 245 c = (u4)crc;
242 c = ~c; 246 c = ~c;
243 while (len && ((int)buf & 3)) { 247 while (len && ((size_t)buf & 3)) {
244 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); 248 c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
245 len--; 249 len--;
246 } 250 }
@@ -280,7 +284,7 @@ local unsigned long crc32_big(crc, buf, len)
280 284
281 c = REV((u4)crc); 285 c = REV((u4)crc);
282 c = ~c; 286 c = ~c;
283 while (len && ((int)buf & 3)) { 287 while (len && ((size_t)buf & 3)) {
284 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); 288 c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
285 len--; 289 len--;
286 } 290 }