1 /* 2 Copyright (c) 1990-2000 Info-ZIP. All rights reserved. 3 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 8 */ 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 12 */ 13 14 /* $Id: crc32.c 1101 2002-09-21 14:54:45Z darkwyrm $ */ 15 16 #define __CRC32_C /* identifies this source module */ 17 18 #include "zip.h" 19 20 #ifndef USE_ZLIB 21 #ifndef ASM_CRC 22 23 #ifndef ZCONST 24 # define ZCONST const 25 #endif 26 27 #ifdef CRC32 28 # undef CRC32 29 #endif 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) 35 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. */ 44 { 45 register ZCONST ulg near *crc_table; 46 47 if (buf == NULL) return 0L; 48 49 crc_table = get_crc_table(); 50 51 crc = crc ^ 0xffffffffL; 52 #ifndef NO_UNROLLED_LOOPS 53 while (len >= 8) { 54 DO8(buf); 55 len -= 8; 56 } 57 #endif 58 if (len) do { 59 DO1(buf); 60 } while (--len); 61 return crc ^ 0xffffffffL; /* (instead of ~c for 64-bit machines) */ 62 } 63 #endif /* !ASM_CRC */ 64 #endif /* !USE_ZLIB */ 65