Lines Matching refs:bd
116 static unsigned int INIT get_bits(struct bunzip_data *bd, char bits_wanted) in get_bits() argument
123 while (bd->inbufBitCount < bits_wanted) { in get_bits()
126 if (bd->inbufPos == bd->inbufCount) { in get_bits()
127 if (bd->io_error) in get_bits()
129 bd->inbufCount = bd->fill(bd->inbuf, BZIP2_IOBUF_SIZE); in get_bits()
130 if (bd->inbufCount <= 0) { in get_bits()
131 bd->io_error = RETVAL_UNEXPECTED_INPUT_EOF; in get_bits()
134 bd->inbufPos = 0; in get_bits()
137 if (bd->inbufBitCount >= 24) { in get_bits()
138 bits = bd->inbufBits&((1 << bd->inbufBitCount)-1); in get_bits()
139 bits_wanted -= bd->inbufBitCount; in get_bits()
141 bd->inbufBitCount = 0; in get_bits()
144 bd->inbufBits = (bd->inbufBits << 8)|bd->inbuf[bd->inbufPos++]; in get_bits()
145 bd->inbufBitCount += 8; in get_bits()
148 bd->inbufBitCount -= bits_wanted; in get_bits()
149 bits |= (bd->inbufBits >> bd->inbufBitCount)&((1 << bits_wanted)-1); in get_bits()
156 static int INIT get_next_block(struct bunzip_data *bd) in get_next_block() argument
166 dbuf = bd->dbuf; in get_next_block()
167 dbufSize = bd->dbufSize; in get_next_block()
168 selectors = bd->selectors; in get_next_block()
169 byteCount = bd->byteCount; in get_next_block()
170 symToByte = bd->symToByte; in get_next_block()
171 mtfSymbol = bd->mtfSymbol; in get_next_block()
175 i = get_bits(bd, 24); in get_next_block()
176 j = get_bits(bd, 24); in get_next_block()
177 bd->headerCRC = get_bits(bd, 32); in get_next_block()
185 if (get_bits(bd, 1)) in get_next_block()
187 origPtr = get_bits(bd, 24); in get_next_block()
195 t = get_bits(bd, 16); in get_next_block()
199 k = get_bits(bd, 16); in get_next_block()
206 groupCount = get_bits(bd, 3); in get_next_block()
214 nSelectors = get_bits(bd, 15); in get_next_block()
221 for (j = 0; get_bits(bd, 1); j++) in get_next_block()
246 t = get_bits(bd, 5)-1; in get_next_block()
258 k = get_bits(bd, 2); in get_next_block()
260 bd->inbufBitCount++; in get_next_block()
296 hufGroup = bd->groups+j; in get_next_block()
364 hufGroup = bd->groups+selectors[selector++]; in get_next_block()
380 while (bd->inbufBitCount < hufGroup->maxLen) { in get_next_block()
381 if (bd->inbufPos == bd->inbufCount) { in get_next_block()
382 j = get_bits(bd, hufGroup->maxLen); in get_next_block()
385 bd->inbufBits = in get_next_block()
386 (bd->inbufBits << 8)|bd->inbuf[bd->inbufPos++]; in get_next_block()
387 bd->inbufBitCount += 8; in get_next_block()
389 bd->inbufBitCount -= hufGroup->maxLen; in get_next_block()
390 j = (bd->inbufBits >> bd->inbufBitCount)& in get_next_block()
398 bd->inbufBitCount += (hufGroup->maxLen - i); in get_next_block()
506 bd->writePos = dbuf[origPtr]; in get_next_block()
507 bd->writeCurrent = (unsigned char)(bd->writePos&0xff); in get_next_block()
508 bd->writePos >>= 8; in get_next_block()
509 bd->writeRunCountdown = 5; in get_next_block()
511 bd->writeCount = dbufCount; in get_next_block()
523 static int INIT read_bunzip(struct bunzip_data *bd, char *outbuf, int len) in read_bunzip() argument
529 if (bd->writeCount < 0) in read_bunzip()
530 return bd->writeCount; in read_bunzip()
533 dbuf = bd->dbuf; in read_bunzip()
534 pos = bd->writePos; in read_bunzip()
535 xcurrent = bd->writeCurrent; in read_bunzip()
541 if (bd->writeCopies) { in read_bunzip()
543 --bd->writeCopies; in read_bunzip()
549 bd->writePos = pos; in read_bunzip()
550 bd->writeCurrent = xcurrent; in read_bunzip()
551 bd->writeCopies++; in read_bunzip()
556 bd->writeCRC = (((bd->writeCRC) << 8) in read_bunzip()
557 ^bd->crc32Table[((bd->writeCRC) >> 24) in read_bunzip()
561 if (bd->writeCopies) { in read_bunzip()
562 --bd->writeCopies; in read_bunzip()
566 if (!bd->writeCount--) in read_bunzip()
578 if (--bd->writeRunCountdown) { in read_bunzip()
580 bd->writeRunCountdown = 4; in read_bunzip()
584 bd->writeCopies = xcurrent; in read_bunzip()
586 bd->writeRunCountdown = 5; in read_bunzip()
589 if (!bd->writeCopies) in read_bunzip()
593 --bd->writeCopies; in read_bunzip()
597 bd->writeCRC = ~bd->writeCRC; in read_bunzip()
598 bd->totalCRC = ((bd->totalCRC << 1) | in read_bunzip()
599 (bd->totalCRC >> 31)) ^ bd->writeCRC; in read_bunzip()
601 if (bd->writeCRC != bd->headerCRC) { in read_bunzip()
602 bd->totalCRC = bd->headerCRC+1; in read_bunzip()
610 previous = get_next_block(bd); in read_bunzip()
612 bd->writeCount = previous; in read_bunzip()
615 bd->writeCRC = 0xffffffffUL; in read_bunzip()
616 pos = bd->writePos; in read_bunzip()
617 xcurrent = bd->writeCurrent; in read_bunzip()
632 struct bunzip_data *bd; in start_bunzip() local
642 bd = *bdp = malloc(i); in start_bunzip()
643 if (!bd) in start_bunzip()
645 memset(bd, 0, sizeof(struct bunzip_data)); in start_bunzip()
647 bd->inbuf = inbuf; in start_bunzip()
648 bd->inbufCount = len; in start_bunzip()
650 bd->fill = fill; in start_bunzip()
652 bd->fill = nofill; in start_bunzip()
659 bd->crc32Table[i] = c; in start_bunzip()
663 i = get_bits(bd, 32); in start_bunzip()
669 bd->dbufSize = 100000*(i-BZh0); in start_bunzip()
671 bd->dbuf = large_malloc(bd->dbufSize * sizeof(int)); in start_bunzip()
672 if (!bd->dbuf) in start_bunzip()
686 struct bunzip_data *bd; in bunzip2() local
706 i = start_bunzip(&bd, inbuf, len, fill); in bunzip2()
709 i = read_bunzip(bd, outbuf, BZIP2_IOBUF_SIZE); in bunzip2()
723 if (bd->headerCRC != bd->totalCRC) in bunzip2()
730 if (!bd) in bunzip2()
732 if (bd->dbuf) in bunzip2()
733 large_free(bd->dbuf); in bunzip2()
735 *pos = bd->inbufPos; in bunzip2()
736 free(bd); in bunzip2()