std::streamsize FileDevice::read(char* s, std::streamsize n)
 {
   PHYSFS_sint64 ret = PHYSFS_read(file, s, 1, PHYSFS_uint32(n));
   if (ret == -1)
     throw Exception(PHYSFS_getLastError());
   return std::streamsize(ret);
 }
Exemplo n.º 2
0
bool
vsFile::ReadLine( vsString *line )
{
	// const int c_bufSize = 1024;
	// char buf[c_bufSize];

	PHYSFS_sint64 filePos = PHYSFS_tell(m_file);
	char peekChar = 'a';
	bool done = false;

	while ( !done && !AtEnd() && peekChar != '\n' && peekChar != 0 )
	{
		if ( PHYSFS_read(m_file, &peekChar, 1, 1) <= 0 )
			done = true;
	}
	PHYSFS_sint64 afterFilePos = PHYSFS_tell(m_file);
	PHYSFS_uint32 bytes = PHYSFS_uint32(afterFilePos - filePos);
	PHYSFS_seek(m_file, filePos);
	if ( bytes > 0 )
	{
		char* buffer = (char*)malloc(bytes+1);
		PHYSFS_uint32 bytesRead = PHYSFS_read(m_file, buffer, 1, bytes);
		vsAssert(bytesRead == bytes, "Didn't read as many bytes as we expected?");
		buffer[bytes-1] = 0;

		*line = buffer;
		while (line->find('\r') != vsString::npos)
		{
			line->erase( line->find('\r') );
		}
		free(buffer);

		return true;
	}
	return false;
}