diff lib/lib.c @ 337:aaafa1ceaa91

Add -N, -I, -L, and -P options to cksum.
author Rob Landley <rob@landley.net>
date Mon, 05 Jan 2009 01:05:43 -0600
parents 83c461db9df7
children 6e03d6a8df23
line wrap: on
line diff
--- a/lib/lib.c	Sun Jan 04 22:45:03 2009 -0600
+++ b/lib/lib.c	Mon Jan 05 01:05:43 2009 -0600
@@ -721,15 +721,16 @@
 
 // Create a 256 entry CRC32 lookup table.
 
-void crc_init(unsigned int *crc_table)
+void crc_init(unsigned int *crc_table, int little_endian)
 {
 	unsigned int i;
 
 	// Init the CRC32 table (big endian)
 	for (i=0; i<256; i++) {
-		unsigned int j, c = i<<24;
+		unsigned int j, c = little_endian ? i : i<<24;
 		for (j=8; j; j--)
-			c=c&0x80000000 ? (c<<1)^0x04c11db7 : (c<<1);
+			if (little_endian) c = (c&1) ? (c>>1)^0xEDB88320 : c>>1;
+			else c=c&0x80000000 ? (c<<1)^0x04c11db7 : (c<<1);
 		crc_table[i] = c;
 	}
 }