From b15b8fa99ae53396145ea540106b74d37797f774 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 5 Jan 2009 01:05:43 -0600 Subject: Add -N, -I, -L, and -P options to cksum. --- lib/bunzip.c | 2 +- lib/lib.c | 7 ++++--- lib/lib.h | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/bunzip.c b/lib/bunzip.c index 18984af4..f860aa64 100644 --- a/lib/bunzip.c +++ b/lib/bunzip.c @@ -609,7 +609,7 @@ int start_bunzip(struct bunzip_data **bdp, int src_fd, char *inbuf, int len) bd->in_fd = src_fd; } - crc_init(bd->crc32Table); + crc_init(bd->crc32Table, 0); // Ensure that file starts with "BZh". for (i=0;i<3;i++) diff --git a/lib/lib.c b/lib/lib.c index f94d6fdf..89c8781b 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -721,15 +721,16 @@ void replace_tempfile(int fdin, int fdout, char **tempname) // 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; } } diff --git a/lib/lib.h b/lib/lib.h index 2fcdaa4d..a473b546 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -96,7 +96,7 @@ void xsendfile(int in, int out); int copy_tempfile(int fdin, char *name, char **tempname); void delete_tempfile(int fdin, int fdout, char **tempname); void replace_tempfile(int fdin, int fdout, char **tempname); -void crc_init(unsigned int *crc_table); +void crc_init(unsigned int *crc_table, int little_endian); // getmountlist.c struct mtab_list { -- cgit v1.2.3