Lines Matching refs:bd

107 static unsigned int INIT get_bits(struct bunzip_data *bd, char bits_wanted)  in get_bits()  argument
114 while (bd->inbufBitCount < bits_wanted) { in get_bits()
117 if (bd->inbufPos == bd->inbufCount) { in get_bits()
118 if (bd->io_error) in get_bits()
120 bd->inbufCount = bd->fill(bd->inbuf, BZIP2_IOBUF_SIZE); in get_bits()
121 if (bd->inbufCount <= 0) { in get_bits()
122 bd->io_error = RETVAL_UNEXPECTED_INPUT_EOF; in get_bits()
125 bd->inbufPos = 0; in get_bits()
128 if (bd->inbufBitCount >= 24) { in get_bits()
129 bits = bd->inbufBits&((1 << bd->inbufBitCount)-1); in get_bits()
130 bits_wanted -= bd->inbufBitCount; in get_bits()
132 bd->inbufBitCount = 0; in get_bits()
135 bd->inbufBits = (bd->inbufBits << 8)|bd->inbuf[bd->inbufPos++]; in get_bits()
136 bd->inbufBitCount += 8; in get_bits()
139 bd->inbufBitCount -= bits_wanted; in get_bits()
140 bits |= (bd->inbufBits >> bd->inbufBitCount)&((1 << bits_wanted)-1); in get_bits()
147 static int INIT get_next_block(struct bunzip_data *bd) in get_next_block() argument
158 dbuf = bd->dbuf; in get_next_block()
159 dbufSize = bd->dbufSize; in get_next_block()
160 selectors = bd->selectors; in get_next_block()
164 i = get_bits(bd, 24); in get_next_block()
165 j = get_bits(bd, 24); in get_next_block()
166 bd->headerCRC = get_bits(bd, 32); in get_next_block()
174 if (get_bits(bd, 1)) in get_next_block()
176 origPtr = get_bits(bd, 24); in get_next_block()
184 t = get_bits(bd, 16); in get_next_block()
188 k = get_bits(bd, 16); in get_next_block()
195 groupCount = get_bits(bd, 3); in get_next_block()
203 nSelectors = get_bits(bd, 15); in get_next_block()
210 for (j = 0; get_bits(bd, 1); j++) in get_next_block()
235 t = get_bits(bd, 5)-1; in get_next_block()
247 k = get_bits(bd, 2); in get_next_block()
249 bd->inbufBitCount++; in get_next_block()
285 hufGroup = bd->groups+j; in get_next_block()
353 hufGroup = bd->groups+selectors[selector++]; in get_next_block()
369 while (bd->inbufBitCount < hufGroup->maxLen) { in get_next_block()
370 if (bd->inbufPos == bd->inbufCount) { in get_next_block()
371 j = get_bits(bd, hufGroup->maxLen); in get_next_block()
374 bd->inbufBits = in get_next_block()
375 (bd->inbufBits << 8)|bd->inbuf[bd->inbufPos++]; in get_next_block()
376 bd->inbufBitCount += 8; in get_next_block()
378 bd->inbufBitCount -= hufGroup->maxLen; in get_next_block()
379 j = (bd->inbufBits >> bd->inbufBitCount)& in get_next_block()
387 bd->inbufBitCount += (hufGroup->maxLen - i); in get_next_block()
495 bd->writePos = dbuf[origPtr]; in get_next_block()
496 bd->writeCurrent = (unsigned char)(bd->writePos&0xff); in get_next_block()
497 bd->writePos >>= 8; in get_next_block()
498 bd->writeRunCountdown = 5; in get_next_block()
500 bd->writeCount = dbufCount; in get_next_block()
512 static int INIT read_bunzip(struct bunzip_data *bd, unsigned char *outbuf, int len) in read_bunzip() argument
518 if (bd->writeCount < 0) in read_bunzip()
519 return bd->writeCount; in read_bunzip()
522 dbuf = bd->dbuf; in read_bunzip()
523 pos = bd->writePos; in read_bunzip()
524 xcurrent = bd->writeCurrent; in read_bunzip()
530 if (bd->writeCopies) { in read_bunzip()
532 --bd->writeCopies; in read_bunzip()
538 bd->writePos = pos; in read_bunzip()
539 bd->writeCurrent = xcurrent; in read_bunzip()
540 bd->writeCopies++; in read_bunzip()
545 bd->writeCRC = (((bd->writeCRC) << 8) in read_bunzip()
546 ^bd->crc32Table[((bd->writeCRC) >> 24) in read_bunzip()
550 if (bd->writeCopies) { in read_bunzip()
551 --bd->writeCopies; in read_bunzip()
555 if (!bd->writeCount--) in read_bunzip()
567 if (--bd->writeRunCountdown) { in read_bunzip()
569 bd->writeRunCountdown = 4; in read_bunzip()
573 bd->writeCopies = xcurrent; in read_bunzip()
575 bd->writeRunCountdown = 5; in read_bunzip()
578 if (!bd->writeCopies) in read_bunzip()
582 --bd->writeCopies; in read_bunzip()
586 bd->writeCRC = ~bd->writeCRC; in read_bunzip()
587 bd->totalCRC = ((bd->totalCRC << 1) | in read_bunzip()
588 (bd->totalCRC >> 31)) ^ bd->writeCRC; in read_bunzip()
590 if (bd->writeCRC != bd->headerCRC) { in read_bunzip()
591 bd->totalCRC = bd->headerCRC+1; in read_bunzip()
599 previous = get_next_block(bd); in read_bunzip()
601 bd->writeCount = previous; in read_bunzip()
604 bd->writeCRC = 0xffffffffUL; in read_bunzip()
605 pos = bd->writePos; in read_bunzip()
606 xcurrent = bd->writeCurrent; in read_bunzip()
621 struct bunzip_data *bd; in start_bunzip() local
631 bd = *bdp = malloc(i); in start_bunzip()
632 if (!bd) in start_bunzip()
634 memset(bd, 0, sizeof(struct bunzip_data)); in start_bunzip()
636 bd->inbuf = inbuf; in start_bunzip()
637 bd->inbufCount = len; in start_bunzip()
639 bd->fill = fill; in start_bunzip()
641 bd->fill = nofill; in start_bunzip()
648 bd->crc32Table[i] = c; in start_bunzip()
652 i = get_bits(bd, 32); in start_bunzip()
658 bd->dbufSize = 100000*(i-BZh0); in start_bunzip()
660 bd->dbuf = large_malloc(bd->dbufSize * sizeof(int)); in start_bunzip()
661 if (!bd->dbuf) in start_bunzip()
675 struct bunzip_data *bd; in bunzip2() local
695 i = start_bunzip(&bd, inbuf, len, fill); in bunzip2()
698 i = read_bunzip(bd, outbuf, BZIP2_IOBUF_SIZE); in bunzip2()
712 if (bd->headerCRC != bd->totalCRC) in bunzip2()
719 if (!bd) in bunzip2()
721 if (bd->dbuf) in bunzip2()
722 large_free(bd->dbuf); in bunzip2()
724 *pos = bd->inbufPos; in bunzip2()
725 free(bd); in bunzip2()