"Fossies" - the Fresh Open Source Software Archive

Member "unrar/getbits.cpp" (4 May 2022, 1087 Bytes) of package /linux/misc/unrarsrc-6.1.7.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "getbits.cpp" see the Fossies "Dox" file reference documentation.

    1 #include "rar.hpp"
    2 
    3 BitInput::BitInput(bool AllocBuffer)
    4 {
    5   ExternalBuffer=false;
    6   if (AllocBuffer)
    7   {
    8     // getbits32 attempts to read data from InAddr, ... InAddr+3 positions.
    9     // So let's allocate 3 additional bytes for situation, when we need to
   10     // read only 1 byte from the last position of buffer and avoid a crash
   11     // from access to next 3 bytes, which contents we do not need.
   12     size_t BufSize=MAX_SIZE+3;
   13     InBuf=new byte[BufSize];
   14 
   15     // Ensure that we get predictable results when accessing bytes in area
   16     // not filled with read data.
   17     memset(InBuf,0,BufSize);
   18   }
   19   else
   20     InBuf=NULL;
   21 }
   22 
   23 
   24 BitInput::~BitInput()
   25 {
   26   if (!ExternalBuffer)
   27     delete[] InBuf;
   28 }
   29 
   30 
   31 void BitInput::faddbits(uint Bits)
   32 {
   33   // Function wrapped version of inline addbits to save code size.
   34   addbits(Bits);
   35 }
   36 
   37 
   38 uint BitInput::fgetbits()
   39 {
   40   // Function wrapped version of inline getbits to save code size.
   41   return getbits();
   42 }
   43 
   44 
   45 void BitInput::SetExternalBuffer(byte *Buf)
   46 {
   47   if (InBuf!=NULL && !ExternalBuffer)
   48     delete[] InBuf;
   49   InBuf=Buf;
   50   ExternalBuffer=true;
   51 }
   52