예제 #1
0
파일: gimli.cpp 프로젝트: dongxu-cug/gimli
uint fileLength(std::fstream & file){
    std::streamoff oldPos = file.tellg();
    file.seekg(0, std::ios::end);
    std::streamoff length = file.tellg();
    file.seekg(oldPos);
    return (uint)length;
}
예제 #2
0
Folder::Ptr Folder::readFolder(std::fstream &file, BSAULong fileNamesLength,
                               BSAULong &endPos)
{
  Folder::Ptr result(new Folder());
  result->m_NameHash = readType<BSAHash>(file);
  result->m_FileCount = readType<unsigned long>(file);
  result->m_Offset = readType<unsigned long>(file);
  std::streamoff pos = file.tellg();

  file.seekg(result->m_Offset - fileNamesLength, fstream::beg);

  result->m_Name = readBString(file);

  for (unsigned long i = 0UL; i < result->m_FileCount; ++i) {
    result->m_Files.push_back(File::Ptr(new File(file, result.get())));
  }

  if (static_cast<unsigned long>(file.tellg()) > endPos) {
    endPos = static_cast<BSAULong>(file.tellg());
  }

  file.seekg(pos);

  return result;
}
예제 #3
0
파일: PeLibAux.cpp 프로젝트: CBaiz/PeLib
	unsigned int fileSize(std::fstream& file)
	{
		unsigned int oldpos = file.tellg();
		file.seekg(0, std::ios::end);
		unsigned int filesize = file.tellg();
		file.seekg(oldpos, std::ios::beg);
		return filesize;
	}
예제 #4
0
bool SnappyFile::rawOpen(const std::string &filename, File::Mode mode)
{
    std::ios_base::openmode fmode = std::fstream::binary;
    if (mode == File::Write) {
        fmode |= (std::fstream::out | std::fstream::trunc);
        createCache(SNAPPY_CHUNK_SIZE);
    } else if (mode == File::Read) {
        fmode |= std::fstream::in;
    }

    m_stream.open(filename.c_str(), fmode);

    //read in the initial buffer if we're reading
    if (m_stream.is_open() && mode == File::Read) {
        m_stream.seekg(0, std::ios::end);
        m_endPos = m_stream.tellg();
        m_stream.seekg(0, std::ios::beg);

        // read the snappy file identifier
        unsigned char byte1, byte2;
        m_stream >> byte1;
        m_stream >> byte2;
        assert(byte1 == SNAPPY_BYTE1 && byte2 == SNAPPY_BYTE2);

        flushReadCache();
    } else if (m_stream.is_open() && mode == File::Write) {
예제 #5
0
파일: File.cpp 프로젝트: AmarSaggu/ORAM
size_t File::GetLength(std::fstream &file)
{
	file.seekg(0, file.end);
	size_t len = file.tellg();
	file.seekg(0, file.beg);
	
	return len;
}
예제 #6
0
UINT64 TargetPhrase::ReadOtherInfoFromFile(UINT64 filePos, std::fstream &fileTPColl)
{
  CHECK(filePos == (UINT64)fileTPColl.tellg());

  UINT64 memUsed = 0;
  fileTPColl.read((char*) &m_filePos, sizeof(UINT64));
  memUsed += sizeof(UINT64);
  CHECK(m_filePos != 0);

  memUsed += ReadAlignFromFile(fileTPColl);
  CHECK((memUsed + filePos) == (UINT64)fileTPColl.tellg());

  memUsed += ReadScoresFromFile(fileTPColl);
  CHECK((memUsed + filePos) == (UINT64)fileTPColl.tellg());

  return memUsed;
}
예제 #7
0
파일: osfile.cpp 프로젝트: HalalUr/Reaping2
bool OsFileImpl::Read( void* Data, size_t Size )
{
    if( !IsValid() )
    {
        return false;
    }
    mFile.read( ( char* )Data, Size );
    mPosition = mFile.tellg();
    return IsValid();
}
예제 #8
0
파일: File.cpp 프로젝트: erenik/engine
String File::GetContents(std::fstream & fileStream)
{
	assert(fileStream.is_open());
	fileStream.seekg( 0, std::ios::beg);
	int start  = (int) fileStream.tellg();
	fileStream.seekg( 0, std::ios::end );
	int fileSize = (int) fileStream.tellg();
	// Empty file?
	if (fileSize == 0)
		return String();
	assert(fileSize);
	char * data = new char [fileSize+2];
	memset(data, 0, fileSize+1);
	fileStream.seekg( 0, std::ios::beg);
	fileStream.read((char*) data, fileSize);
	String strData(data);
	delete[] data;
	return strData;
}
예제 #9
0
/*!
 * Copies entire file into a char array
 * @param[in]   str     file stream to be copied; file nneds already to be opened
 * @param[out]  buffer  char array containing entire array
 * @param[out]  length  number of elements which hvae benn copied
 */
void copyUntilEOFInString( std::fstream &str, char*& buffer, int &length) {

    std::fstream::pos_type   position_insert, position_eof ;

    position_insert = str.tellg() ;

    str.seekg(0, str.end);
    position_eof = str.tellg();

    length = position_eof - position_insert ;
    buffer = new char[length] ;

    str.seekg(position_insert);
    str.read(buffer,length ) ;

    str.seekg(position_insert);

    return;
};
예제 #10
0
Block readBlockFromFile(std::fstream& f) {
  Block b {};
  BlockOffset off = f.tellg();
  f.read(reinterpret_cast<char *>(&b.data), sizeof(b.data));
  for(auto& o : b.offsets) {
      f.read(reinterpret_cast<char *>(&o), sizeof(o));
  }
  f.seekg(off, f.beg);
  return b;  
}
예제 #11
0
파일: osfile.cpp 프로젝트: HalalUr/Reaping2
bool OsFileImpl::Write( void const* Src, size_t Size )
{
    if( !IsValid() )
    {
        return false;
    }
    mSize += Size;
    mFile.write( ( char const* )Src, Size );
    mPosition = mFile.tellg();
    return IsValid();
}
예제 #12
0
	SeekableFileStream(const char *name) {
		_fileStream = new std::fstream();
		_fileStream->open(name, std::fstream::in | std::fstream::binary);
		if (_fileStream->fail()) {
			_length = -1;
		} else {
			_fileStream->seekg(0, std::ios_base::end);
			_length = _fileStream->tellg();
			_fileStream->seekg(0, std::ios_base::beg);
		}
	}
예제 #13
0
void IndexDataStructure::loadAt(std::fstream & _input_file, std::streampos _position)
{
    // remember the read file position
    std::streampos r_pos = _input_file.tellg();

    // go to asked read position
    _input_file.seekg(_position);
    readToNext(_input_file);

    // restore original read position
    _input_file.seekg(r_pos);
}
예제 #14
0
void MeshFileLoader::ChunkWrite( std::fstream &filestr, char *src, unsigned size, unsigned chunksize )
{
    if (!size)
        return;

    int filesize = (int)filestr.tellg();
    int chunks = size / chunksize;
    for ( int i = 0; i < chunks; ++i )
    {
        filestr.write( src + i * chunksize, chunksize );
    }
    filestr.write( src + chunks * chunksize, size % chunksize );
}
예제 #15
0
void IndexDataStructure::readToNext(std::fstream & _input_file)
{
    m_is_indexed = true;
    m_index_position = _input_file.tellg();

    _input_file.read((char *)(&m_count), sizeof(m_count));
    _input_file.read((char *)(m_keys), sizeof(m_keys[0]) * m_max_count);
    _input_file.read((char *)(m_addresses), sizeof(m_addresses[0]) * m_max_count);
    _input_file.read((char *)(&m_next_sibling_address), sizeof(m_next_sibling_address));

    // skip free block space
    _input_file.seekg(m_block_size - m_real_data_size, _input_file.cur);
}
예제 #16
0
 CXXFStream(const char* _name,std::ios_base::openmode _mode):file(_name,_mode| std::ios::binary) {
     if(!file) {
         size = 0;
         return;
     }
     file.seekg(0, std::ios::end);
     size = (long)file.tellg();
     file.seekg(0, std::ios::beg);//将指针重新定位到文件开头
     int i;
     for(i=0; i<10; ++i) //0~9
         ox2d[i] = i;
     for(i=49; i<55; ++i)    //a~f、A~F
         ox2d[i] = ox2d[i-32] = i-39;
 }
예제 #17
0
bool CLayer:: read_layer_multi_contour_with_z(std::fstream& fin)
{

  int pos=-1;
  float levelID;
  int contourID;
  bool result=true;

  if (fin.good())
  {
    pos=fin.tellg();
    fin>>levelID;
    fin>>contourID;
    fin.seekg(pos);
  }
예제 #18
0
파일: main.cpp 프로젝트: Rohansi/LoonyOS
exp bool Open(const char* fname, unsigned int pO, unsigned int pLen) {
    partitionOffset = pO;
    partitionLength = pLen;

    // Open the image
    f.open(fname, std::ios::in | std::ios::out | std::ios::binary);

    if (!f.is_open()) {
        LastError("Open", "Failed to open disk");
        return false;
    }

    f.seekg(0, std::ios::end);
    fsize = (size_t)f.tellg();
    f.seekg(0);

    // Allocate a buffer
    sectorBuffer = new char[SECTOR_SIZE];

    // Read the BPB
    if (!ReadBPB()) {
        LastError("Open", "Failed to read the BPB");
        return false;
    }

    // Read filesystem info
    fsInfo = new FileSystemInfo;
    ReadSector((char*)fsInfo, bpb->clusterFSInfo);

    // Load the root directory
    if (!DirOpenRoot()) {
        LastError("Open", "Failed to load the root directory");
        return false;
    }

    volumeId = new char[DOS83_MAX_LEN + 1];
    ReadSector(sectorBuffer, ClusterToSector(bpb->clusterRoot));
    DirectoryEntry* entry = FindEntryAttribute(ATTRIB_VOLUME_ID, &directory);
    if (entry) {
        memcpy(volumeId, entry->name, DOS83_MAX_LEN);
        volumeId[11] = 0;
    }

    return true;
}
예제 #19
0
bool SnappyFile::rawOpen(const std::string &filename)
{
    std::ios_base::openmode fmode = std::fstream::binary
                                  | std::fstream::in;

    m_stream.open(filename.c_str(), fmode);

    //read in the initial buffer if we're reading
    if (m_stream.is_open()) {
        m_stream.seekg(0, std::ios::end);
        m_endPos = m_stream.tellg();
        m_stream.seekg(0, std::ios::beg);

        // read the snappy file identifier
        unsigned char byte1, byte2;
        m_stream >> byte1;
        m_stream >> byte2;
        assert(byte1 == SNAPPY_BYTE1 && byte2 == SNAPPY_BYTE2);

        flushReadCache();
    }
예제 #20
0
std::streampos search_forward ( std::fstream & _bs, const std::string & sample )
{
	size_t match ( 0 );
	cSaveIStreamPosition ip ( &_bs );
	streampos result ( static_cast<streampos>( -1 ) );
	cSaveStreamExceptions se ( &_bs, std::ios_base::goodbit );
	
	for( int ch( EOF ); match < sample.length(); match++ )
	{
		ch = _bs.get();
		if( ch == EOF )
			break;
		else if( ch != sample[match] )
			match = 0;
	}
	if( match == sample.length() )
		result = _bs.tellg() - static_cast<streampos>( match );
	
	_bs.clear();
	
	return result;
}
예제 #21
0
파일: main.cpp 프로젝트: zwug/homework
void printFile(std::fstream &file, const char filename[]) {
    file.seekg(0, file.end);
    int fileSize = file.tellg();
    contact contacts[ROWS_TOTAL_COUNT];
    std::ifstream fileToRead;
    fileToRead.open(filename, std::ios::binary | std::ios::in);
    if (fileToRead.fail()) {
        std::cout << "Не удается открыть файл\n";
        exit(1);
    }
    fileToRead.seekg(0, fileToRead.beg);
    bool formatError = false;

    std::cout << std::endl << "***************** Prinitng file ****************" << std::endl << std::endl;
    for (int i = 0; i < fileSize / ROW_LENGTH; i++) {
        fileToRead.read(contacts[i].firstName, NAME_LENGTH);
        fileToRead.read(contacts[i].lastName, NAME_LENGTH);
        fileToRead.read(contacts[i].phone, PHONE_LENGTH);

        std::cout << std::setw(NAME_LENGTH) << contacts[i].firstName << " | ";
        std::cout << std::setw(NAME_LENGTH) << contacts[i].lastName << " | ";
        std::cout << contacts[i].phone << std::endl;

        if (contacts[i].phone[1] != '(' || contacts[i].phone[5] != ')' || contacts[i].phone[9] != '-') {
            formatError = true;
        }
    }
    std::cout << std::endl << "***************** end of file ******************" << std::endl << std::endl;
    std::cout << "Length of the file should be " << ROW_LENGTH * ROWS_TOTAL_COUNT << ", got " << fileSize << std::endl;

    if (!formatError) {
        std::cout << "Correct formatting" << std::endl;
    }
    else {
        std::cout << "Error: incorrect formatting" << std::endl;
    }
    fileToRead.close();
}
예제 #22
0
파일: VTK.cpp 프로젝트: flbernard/bitpit
/*!
 * Reads data array from stream and stores in field information
 * @param[in]   str     output stream
 * @param[out]   field_   field information
 */
bool  VTK::readDataArray( std::fstream &str, VTKField &field_  ){

    std::string              line_ ;

    while( getline(str, line_)  ){

        if( bitpit::utils::keywordInString( line_, field_.getName() ) ){
            if( vtk::convertStringToDataArray( line_, field_  ) ){

                if( field_.getCodification() == VTKFormat::ASCII) {
                    field_.setPosition( str.tellg() ) ;
                };

                return true ;
            };

        };

    };

    return false ; 

};
예제 #23
0
void C3Sav::Impl::initEntryExit(std::fstream &f, PlayerCityPtr ioCity)
{
    unsigned int size = ioCity->tilemap().size();

    const unsigned int savePos = f.tellg();

    // init road entry/exit point
    unsigned short int i = 0;
    unsigned short int j = 0;
    f.seekg(1236, std::ios::cur);
    f.read((char*)&i, 2);
    f.read((char*)&j, 2);

    BorderInfo borderInfo;

    borderInfo.roadEntry = TilePos( i, size - j - 1 );

    f.read((char*)&i, 2);
    f.read((char*)&j, 2);
    borderInfo.roadExit = TilePos( i, size - j - 1 );

    // init boat entry/exit point
    f.seekg(savePos, std::ios::beg);
    f.seekg(1276, std::ios::cur);
    f.read((char*)&i, 2);
    f.read((char*)&j, 2);
    borderInfo.boatEntry = TilePos( i, size - j - 1 );

    f.read((char*)&i, 2);
    f.read((char*)&j, 2);
    borderInfo.boatExit = TilePos( i, size - j - 1);

    ioCity->setBorderInfo( borderInfo );

    f.seekg(savePos, std::ios::beg);
}
예제 #24
0
	/**
	 * Obtains the current value of the stream position indicator of the
	 * stream.
	 *
	 * @return the current position indicator, or -1 if an error occurred.
	 */
	virtual int32 pos() const {
		return _stream->tellg();
	}
예제 #25
0
파일: VTK.cpp 프로젝트: flbernard/bitpit
/*!
 * Reads data headers from strean.
 * All field information available in file are stored.
 * @param[in]   str     output stream
 */
void VTK::readDataHeader( std::fstream &str ){


    std::fstream::pos_type   pos_ ;

    VTKLocation             location;
    std::string             locationString ;
    std::string             line, loc_;
    std::stringstream       ss;

    bool                    read ;

    VTKField                temp ;
    VTKField**              ptemp ;


    for( int i=0; i<2; i++){

        ss.str("") ;
        if( i== 0) {
            location = VTKLocation::POINT;
            locationString = "Point" ;
        } else if( i== 1) {
            location = VTKLocation::CELL;
            locationString = "Cell" ;
        }


        temp.setLocation( location ) ;

        ss << "</" << locationString << "Data>" ;
        loc_ = ss.str();

        read= true ; 
        if( ! getline( str, line) ) read = false ;
        if( bitpit::utils::keywordInString( line, loc_) ) read=false ;


        while( read ){
            if( vtk::convertStringToDataArray( line, temp  ) ) {

                if( temp.getCodification() == VTKFormat::ASCII) {
                    pos_ = str.tellg() ;
                }

                else{
                    pos_ =  0 ; 
                };

                temp.setPosition( pos_ ) ;

                if( ! getFieldByName( temp.getName(), ptemp )) {
                    data.push_back( new VTKField( temp ) ) ;
                }

                else{
                    (*ptemp)->setOffset( temp.getOffset() ) ;
                    (*ptemp)->setLocation( temp.getLocation() ) ;
                    (*ptemp)->setDataType( temp.getDataType() ) ;
                    (*ptemp)->setFieldType( temp.getFieldType() ) ;
                    (*ptemp)->setCodification( temp.getCodification() ) ;

                };

            };

            if( ! getline( str, line) ) read = false ;
            if( bitpit::utils::keywordInString( line, loc_) ) read=false ;
        }; 

    };

    return ;
};
예제 #26
0
파일: ULTI_File.cpp 프로젝트: wizebin/ulti
size_t getfsize(std::fstream & file){
    file.seekg(0, std::ios::end);
    size_t size = (size_t)file.tellg();
    file.seekg(0);
    return size;
}
예제 #27
0
파일: osfile.cpp 프로젝트: HalalUr/Reaping2
bool OsFileImpl::SetPosition( size_t Pos )
{
    mFile.seekg( Pos, std::ios_base::beg );
    mPosition = Pos;
    return size_t( mFile.tellg() ) == Pos;
}
예제 #28
0
int checkBitFile(std::fstream &file) {
    char key;
    uint8_t c_length[2];
    uint16_t length;

    file.seekg(0, std::ios::beg);
    
    // Field 1
    file.read((char*)c_length, 2);
    length = c_length[1];
    length += c_length[0] << 8;
    if (length != 9) {
        std::cerr << __PRETTY_FUNCTION__ << " -> Wrong header length!" << std::endl;
        return 1;
    }
    
    char *field1 = new char[length];
    file.read(field1, length);
     
    // Field 2
    file.read((char*)c_length, 2);
    length = c_length[1];
    length += c_length[0] << 8;
    char *field2 = new char[length];
    file.read(field2, length);

    // Field 3
    file.read((char*)c_length, 2);
    length = c_length[1];
    length += c_length[0] << 8;
    char *field3 = new char[length];
    file.read(field3, length);
    
    // Field 4
    file.read(&key, 1);
    file.read((char*)c_length, 2);
    length = c_length[1];
    length += c_length[0] << 8;
    char *field4 = new char[length];
    file.read(field4, length);
    
    // Field 5
    file.read(&key, 1);
    file.read((char*)c_length, 2);
    length = c_length[1];
    length += c_length[0] << 8;
    char *field5 = new char[length];
    file.read(field5, length);
    
    // Field 6
    file.read(&key, 1);
    file.read((char*)c_length, 2);
    length = c_length[1];
    length += c_length[0] << 8;
    char *field6 = new char[length];
    file.read(field6, length);
    
    // Field 7
    file.read(&key, 1);
    uint8_t c_data_length[4];
    file.read((char*)c_data_length, 4);
    uint32_t data_length = 0;
    data_length = c_data_length[3];
    data_length += c_data_length[2] << 8;
    data_length += c_data_length[1] << 16;
    data_length += c_data_length[0] << 24;
   
    // Remaining file size
    size_t beg, end, size;
    beg = file.tellg();
    file.seekg(0, std::ios::end);
    end = file.tellg();
    size = end - beg;   
    file.seekg(0, std::ios::beg);

    std::cout << "=========================================" << std::endl;
    std::cout << "File info:" << std::endl;
    std::cout << " Design Name: " << field3 << std::endl;
    std::cout << " Device:      " << field4 << std::endl;
    std::cout << " Timestamp:   " << field5 << " " << field6 << std::endl;
    std::cout << " Data size:   " << data_length << std::endl;
    std::cout << "=========================================" << std::endl;
   
    std::string device(field4, 13);
    if (device != "6slx45tfgg484") {
        std::cerr << __PRETTY_FUNCTION__ << " -> Wrong device type!" << std::endl;
        return 1;
    }
    
    if (data_length-size != 0) {
        std::cerr << __PRETTY_FUNCTION__ << " -> Real size and size don't match!" << std::endl;
        return 1;
    }
    
    delete field1;
    delete field2;
    delete field3;
    delete field4;
    delete field5;
    delete field6;
    return 0;
}