comparison lib/bunzip.c @ 334:83c461db9df7

Check in crc_init needed by cksum. (Oops.)
author Rob Landley <rob@landley.net>
date Sat, 03 Jan 2009 18:15:18 -0600
parents b094b81830b0
children aaafa1ceaa91
comparison
equal deleted inserted replaced
333:d5d8f9a6e649 334:83c461db9df7
590 // Allocate the structure, read file header. If !len, src_fd contains 590 // Allocate the structure, read file header. If !len, src_fd contains
591 // filehandle to read from. Else inbuf contains data. 591 // filehandle to read from. Else inbuf contains data.
592 int start_bunzip(struct bunzip_data **bdp, int src_fd, char *inbuf, int len) 592 int start_bunzip(struct bunzip_data **bdp, int src_fd, char *inbuf, int len)
593 { 593 {
594 struct bunzip_data *bd; 594 struct bunzip_data *bd;
595 unsigned int i, j, c; 595 unsigned int i;
596 596
597 // Figure out how much data to allocate. 597 // Figure out how much data to allocate.
598 i = sizeof(struct bunzip_data); 598 i = sizeof(struct bunzip_data);
599 if (!len) i += IOBUF_SIZE; 599 if (!len) i += IOBUF_SIZE;
600 600
607 } else { 607 } else {
608 bd->inbuf = (char *)(bd+1); 608 bd->inbuf = (char *)(bd+1);
609 bd->in_fd = src_fd; 609 bd->in_fd = src_fd;
610 } 610 }
611 611
612 // Init the CRC32 table (big endian) 612 crc_init(bd->crc32Table);
613 for (i=0; i<256; i++) {
614 c = i<<24;
615 for (j=8; j; j--)
616 c=c&0x80000000 ? (c<<1)^0x04c11db7 : (c<<1);
617 bd->crc32Table[i] = c;
618 }
619 613
620 // Ensure that file starts with "BZh". 614 // Ensure that file starts with "BZh".
621 for (i=0;i<3;i++) 615 for (i=0;i<3;i++)
622 if (get_bits(bd,8)!="BZh"[i]) return RETVAL_NOT_BZIP_DATA; 616 if (get_bits(bd,8)!="BZh"[i]) return RETVAL_NOT_BZIP_DATA;
623 617