X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fdecompress.c;h=6d4b41e2285512d33ad21e8a360a0d61931ca198;hp=9a08621aea7e5b53aa93870537906c6109cf03b8;hb=1ab60207e56968e480be6400c67844017598b7dd;hpb=e78f0d2a97781f3c5f242417c747fdc4eef43cdf;ds=sidebyside diff --git a/src/decompress.c b/src/decompress.c index 9a08621a..6d4b41e2 100644 --- a/src/decompress.c +++ b/src/decompress.c @@ -26,48 +26,6 @@ #include "decompress.h" #include -/* Reads @n bytes from the bitstream @stream into the location pointed to by @dest. - * The bitstream must be 16-bit aligned. */ -int bitstream_read_bytes(struct input_bitstream *stream, size_t n, void *dest) -{ - /* Precondition: The bitstream is 16-byte aligned. */ - wimlib_assert2(stream->bitsleft % 16 == 0); - - u8 *p = dest; - - /* Get the bytes currently in the buffer variable. */ - while (stream->bitsleft != 0) { - if (n-- == 0) - return 0; - *p++ = bitstream_peek_bits(stream, 8); - bitstream_remove_bits(stream, 8); - } - - /* Get the rest directly from the pointer to the data. Of course, it's - * necessary to check there are really n bytes available. */ - if (n > stream->data_bytes_left) { - ERROR("Unexpected end of input when reading %zu bytes from " - "bitstream (only have %u bytes left)", - n, stream->data_bytes_left); - return 1; - } - memcpy(p, stream->data, n); - stream->data += n; - stream->data_bytes_left -= n; - - /* It's possible to copy an odd number of bytes and leave the stream in - * an inconsistent state. Fix it by reading the next byte, if it is - * there. */ - if ((n & 1) && stream->data_bytes_left != 0) { - stream->bitsleft = 8; - stream->data_bytes_left--; - stream->bitbuf |= (input_bitbuf_t)(*stream->data) << - (sizeof(input_bitbuf_t) * 8 - 8); - stream->data++; - } - return 0; -} - /* * Builds a fast huffman decoding table from an array that gives the length of * the codeword for each symbol in the alphabet. Originally based on code @@ -356,7 +314,7 @@ int read_huffsym_near_end_of_input(struct input_bitstream *istream, do { if (bitsleft == 0) { ERROR("Input stream exhausted"); - return 1; + return -1; } key_bits = sym + bitstream_peek_bits(istream, 1); bitstream_remove_bits(istream, 1);