diff options
author | Rob Landley <rob@landley.net> | 2006-04-10 17:07:15 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-04-10 17:07:15 +0000 |
commit | c57ec37959390ff2e43faa5e4dd5281b2923ced3 (patch) | |
tree | 8325e7bd6a9a270e931b383d33b5901751dd2a5e /archival/gzip.c | |
parent | 998f4493756423877217239d2cc42eb8b83d50b3 (diff) | |
download | busybox-w32-c57ec37959390ff2e43faa5e4dd5281b2923ced3.tar.gz busybox-w32-c57ec37959390ff2e43faa5e4dd5281b2923ced3.tar.bz2 busybox-w32-c57ec37959390ff2e43faa5e4dd5281b2923ced3.zip |
Patch from Rob Sullivan to consolidate crc32 table generation.
Diffstat (limited to 'archival/gzip.c')
-rw-r--r-- | archival/gzip.c | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index fa6e85b66..41ed3a2c7 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -293,6 +293,7 @@ static int ofd; /* output file descriptor */ | |||
293 | static unsigned insize; /* valid bytes in inbuf */ | 293 | static unsigned insize; /* valid bytes in inbuf */ |
294 | static unsigned outcnt; /* bytes in output buffer */ | 294 | static unsigned outcnt; /* bytes in output buffer */ |
295 | 295 | ||
296 | static uint32_t *crc_32_tab; | ||
296 | 297 | ||
297 | /* Output a 16 bit value, lsb first */ | 298 | /* Output a 16 bit value, lsb first */ |
298 | static void put_short(ush w) | 299 | static void put_short(ush w) |
@@ -344,32 +345,13 @@ static void write_buf(int fd, void *buf, unsigned cnt) | |||
344 | * pointer, then initialize the crc shift register contents instead. | 345 | * pointer, then initialize the crc shift register contents instead. |
345 | * Return the current crc in either case. | 346 | * Return the current crc in either case. |
346 | */ | 347 | */ |
347 | static ulg updcrc(uch * s, unsigned n) | 348 | static uint32_t updcrc(uch * s, unsigned n) |
348 | { | 349 | { |
349 | static ulg crc = (ulg) 0xffffffffL; /* shift register contents */ | 350 | static uint32_t crc = ~0; /* shift register contents */ |
350 | register ulg c; /* temporary variable */ | 351 | uint32_t c; /* temporary variable */ |
351 | static unsigned long crc_32_tab[256]; | ||
352 | |||
353 | if (crc_32_tab[1] == 0x00000000L) { | ||
354 | unsigned long csr; /* crc shift register */ | ||
355 | const unsigned long e = 0xedb88320L; /* polynomial exclusive-or pattern */ | ||
356 | int i; /* counter for all possible eight bit values */ | ||
357 | int k; /* byte being shifted into crc apparatus */ | ||
358 | |||
359 | /* Compute table of CRC's. */ | ||
360 | for (i = 1; i < 256; i++) { | ||
361 | csr = i; | ||
362 | /* The idea to initialize the register with the byte instead of | ||
363 | * zero was stolen from Haruhiko Okumura's ar002 | ||
364 | */ | ||
365 | for (k = 8; k; k--) | ||
366 | csr = csr & 1 ? (csr >> 1) ^ e : csr >> 1; | ||
367 | crc_32_tab[i] = csr; | ||
368 | } | ||
369 | } | ||
370 | 352 | ||
371 | if (s == NULL) { | 353 | if (s == NULL) { |
372 | c = 0xffffffffL; | 354 | c = ~0; |
373 | } else { | 355 | } else { |
374 | c = crc; | 356 | c = crc; |
375 | if (n) | 357 | if (n) |
@@ -378,7 +360,7 @@ static ulg updcrc(uch * s, unsigned n) | |||
378 | } while (--n); | 360 | } while (--n); |
379 | } | 361 | } |
380 | crc = c; | 362 | crc = c; |
381 | return c ^ 0xffffffffL; /* (instead of ~c for 64-bit machines) */ | 363 | return ~c; |
382 | } | 364 | } |
383 | 365 | ||
384 | /* bits.c -- output variable-length bit strings | 366 | /* bits.c -- output variable-length bit strings |
@@ -1223,6 +1205,9 @@ int gzip_main(int argc, char **argv) | |||
1223 | ALLOC(uch, window, 2L * WSIZE); | 1205 | ALLOC(uch, window, 2L * WSIZE); |
1224 | ALLOC(ush, tab_prefix, 1L << BITS); | 1206 | ALLOC(ush, tab_prefix, 1L << BITS); |
1225 | 1207 | ||
1208 | /* Initialise the CRC32 table */ | ||
1209 | crc_32_tab = bb_crc32_filltable(0); | ||
1210 | |||
1226 | clear_bufs(); | 1211 | clear_bufs(); |
1227 | part_nb = 0; | 1212 | part_nb = 0; |
1228 | 1213 | ||
@@ -2416,7 +2401,7 @@ static void set_file_type(void) | |||
2416 | */ | 2401 | */ |
2417 | 2402 | ||
2418 | 2403 | ||
2419 | static ulg crc; /* crc on uncompressed file data */ | 2404 | static uint32_t crc; /* crc on uncompressed file data */ |
2420 | static long header_bytes; /* number of bytes in gzip header */ | 2405 | static long header_bytes; /* number of bytes in gzip header */ |
2421 | 2406 | ||
2422 | static void put_long(ulg n) | 2407 | static void put_long(ulg n) |