Logo Search packages:      
Sourcecode: pbzip2 version File versions  Download package

BZ2StreamScanner::CharType * pbzip2::BZ2StreamScanner::locateHeaderPrefixInBuff (  ) [private]

Locate BZh header prefix in buffer. In case of first search - just check the beginning of buffer and signal error if it doesn't match to headers.

Returns:
pointer to BZh header prefix if located. getInBuffEnd() if not. failure() and getErrState() will indicate error if such occurred.

Definition at line 345 of file BZ2StreamScanner.cpp.

{
      size_t prefixLen = 3;

      #ifdef PBZIP_DEBUG
      fprintf( stderr, " start locateHeaderPrefixInBuff; " );
      printCurrentState();
      fprintf( stderr, "\n" );
      #endif

      // first search
      if ( !isBz2HeaderFound() )
      {
            if ( ( getInBuffSearchPtr() != getInBuffBegin() ) ||
                  ( getInBuffSize() < _bz2Header.size() ) )
            {
                  _errState |= ERR_INVALID_FILE_FORMAT;
                  _inBuffSearchPtr = getInBuffEnd();
            }
            else if ( _bz2Header.compare( 0, prefixLen, getInBuffSearchPtr(), prefixLen ) == 0 )
            {
                  // header prefix found
            }
            else
            {
                  _errState |= ERR_INVALID_FILE_FORMAT;
                  _inBuffSearchPtr = getInBuffEnd();
            }
      }
      else
      {
            _inBuffSearchPtr = std::search( getInBuffSearchPtr(), getInBuffEnd(),
                        _bz2Header.begin(), _bz2Header.begin() + prefixLen );
      }

      #ifdef PBZIP_DEBUG
      if ( getInBuffSearchPtr() != getInBuffEnd() )
      {
            fprintf( stderr, " end locateHeaderPrefixInBuff - header prefix found; " );
      }
      else
      {
            fprintf( stderr, " end locateHeaderPrefixInBuff - header prefix not found; " );
      }
      printCurrentState();
      fprintf( stderr, "\n" );
      #endif
      
      return getInBuffSearchPtr();
}

Generated by  Doxygen 1.6.0   Back to index