Example #1
0
	SQInteger Len() {
		SQInteger prevpos=Tell();
		Seek(0,SQ_SEEK_END);
		SQInteger size=Tell();
		Seek(prevpos,SQ_SEEK_SET);
		return size;
	}
Example #2
0
// Determines the length of the stream.
void StreamFile::GetLength()
{
	size_t current_position = Tell();
	Seek(0, SEEK_END);
	length = Tell();
	Seek(current_position, SEEK_SET);
}
Example #3
0
long cFile::GetSize(void) const
{
	ASSERT(IsOpen());

	if (!IsOpen())
	{
		return -1;
	}

	long CurPos = Tell();
	if (CurPos < 0)
	{
		return -1;
	}
	if (fseek(m_File, 0, SEEK_END) != 0)
	{
		return -1;
	}
	long res = Tell();
	if (fseek(m_File, static_cast<long>(CurPos), SEEK_SET) != 0)
	{
		return -1;
	}
	return res;
}
int     FILEFile::Seek(int offset, int origin)
{
    int newOrigin = 0;
    switch(origin)
    {
    case Seek_Set: newOrigin = SEEK_SET; break;
    case Seek_Cur: newOrigin = SEEK_CUR; break;
    case Seek_End: newOrigin = SEEK_END; break;
    }

    if (newOrigin == SEEK_SET && offset == Tell())
        return Tell();

    if (fseek (fs, offset, newOrigin))
    {
#ifdef OVR_FILE_VERIFY_SEEK_ERRORS
        OVR_ASSERT(0);
#endif
        return -1;
    }
    
#ifdef OVR_FILE_VERIFY_SEEK_ERRORS
    // Track file position after seeks for read verification later.
    switch(origin)
    {
    case Seek_Set:  TestPos = offset;       break;
    case Seek_Cur:  TestPos += offset;      break;    
    case Seek_End:  TestPos = FileTestLength + offset; break;
    }
    OVR_ASSERT((int)TestPos == Tell());
#endif

    return (int)Tell();
}
  float ClampedTell ()
  {
    float offset = Tell ().cast<float> ();

    if (looped) return fmod (offset, duration);
    else        return offset < duration ? Tell ().cast<float> () : duration;
  }  
Example #6
0
mEResult mCFileStream::Read( mCString & a_strDest )
{
    // Note: m_arrBuffer (a mCCharArray) is guaranteed to be 0-terminated.
    if ( !( m_enuOpenMode & mEFileOpenMode_Read ) )
    {
        MI_ERROR( mCStreamError, EFileNotOpen, "File is not open for reading operations." );
        return mEResult_False;
    }
    if ( Tell() == GetSize() )
    {
        MI_ERROR( mCStreamError, ESizeExceeded, "File size exceeded when reading binary data." );
        return mEResult_False;
    }
    MILPCChar const pcText = m_arrBuffer.GetBuffer() + m_uOffset;
    MIUInt const uSize = static_cast< MIUInt >( g_strlen( pcText ) );
    a_strDest.SetText( pcText, uSize );
    m_uOffset += uSize;
    if ( m_uOffset == m_arrBuffer.GetCount() )
    {
        if ( Tell() == GetSize() )
            return mEResult_Ok;
        Buffer( Tell() );
        mCString strTemp;
        Read( strTemp );
        a_strDest.Append( strTemp );
    }
    else
    {
        m_uOffset += 1;
    }
    return mEResult_Ok;
}
Example #7
0
mEResult mCFileStream::Read( MILPVoid a_pDest, MIUInt a_uSize )
{
    if ( m_uOffset + a_uSize <= m_arrBuffer.GetCount() )
    {
        g_memcpy( a_pDest, ( m_arrBuffer.GetBuffer() + m_uOffset ), a_uSize );
        m_uOffset += a_uSize;
        return mEResult_Ok;
    }
    if ( !( m_enuOpenMode & mEFileOpenMode_Read ) )
    {
        MI_ERROR( mCStreamError, EFileNotOpen, "File is not open for reading operations." );
        return mEResult_False;
    }
    if ( ( Tell() + a_uSize ) > GetSize() )
    {
        MI_ERROR( mCStreamError, ESizeExceeded, "File size exceeded when reading binary data." );
        return mEResult_False;
    }
    MIByte * pDest = static_cast< MIByte * >( a_pDest );
    for ( ; ; )
    {
        MIUInt const uSize = g_min( a_uSize, ( m_arrBuffer.GetCount() - m_uOffset ) );
        g_memcpy( pDest, ( m_arrBuffer.GetBuffer() + m_uOffset ), uSize );
        pDest += uSize;
        a_uSize -= uSize;
        m_uOffset += uSize;
        if ( !a_uSize )
            break;
        Buffer( Tell() );
    }
    return mEResult_Ok;
}
Example #8
0
u32 vfsStreamMemory::Read(void* dst, u32 size)
{
	if(!Memory.IsGoodAddr(m_addr + Tell(), size)) return 0;

	memcpy(dst, &Memory[m_addr + Tell()], size);

	return vfsStream::Read(dst, size);
}
Example #9
0
			virtual int GetSize( )
			{
				int curpos = Tell( );
				Seek( 0, SeekOrigin::END );
				int size = Tell( );
				Seek( curpos, SeekOrigin::SET );
				return size;
			};
size_t BinaryReader::GetSize()
{
    size_t now = Tell();
    Seek(0,SEEK_END);
    size_t size = Tell();
    Seek(now,SEEK_SET);
    return size;
}
int64 IFileHandle::Size()
{
	int64 Current = Tell();
	SeekFromEnd();
	int64 Result = Tell();
	Seek(Current);
	return Result;
}
Example #12
0
int sprawl::filesystem::File::FileSize()
{
	int current = Tell();
	Seek(0, RelativeTo::End);
	int size = Tell();
	Seek(current, RelativeTo::Beginning);
	return size;
}
Example #13
0
u32 vfsStreamMemory::Write(const void* src, u32 size)
{
	if(!Memory.IsGoodAddr(m_addr + Tell(), size)) return 0;

	memcpy(&Memory[m_addr + Tell()], src, size);

	return vfsStream::Write(src, size);
}
Example #14
0
int XFile::GetLength()
{
	if(m_file==XNULL) return 0;
	int v=Tell();
	Seek(0,XSEEK_END);
	int l=Tell();
	Seek(v,XSEEK_SET);
	return l;
}
Example #15
0
u64 vfsStream::GetSize()
{
	u64 last_pos = Tell();
	Seek(0, vfsSeekEnd);
	u64 size = Tell();
	Seek(last_pos, vfsSeekSet);

	return size;
}
Example #16
0
size_t DiskFile::GetFileSize()
{
	ASSERT(IsOpen());
	size_t currentPos = Tell();
	Seek(0, FILESEEK_END);
	size_t filesize = Tell();
	Seek(currentPos, FILESEEK_BEGINNING);
	return filesize;
}
Example #17
0
int64 f9FileDisk::DoSize()
{
	int64 p = Tell(); 
	if(p == F9_FAIL) return F9_FAIL;
	if(!Seek(0, SEEK_END)) return F9_FAIL;
	int64 s = Tell();
	if(!Seek(p)) return F9_FAIL;
	return s;
}
Example #18
0
void TFile::InternalSeek(int iOffset, TFileSeekMode Mode)
{
	DEBUG_VERIFY(IsOpen());

	if(m_flOpenFlags & FOF_TEXT)
	{
		if(Mode == FSM_BEGIN)
		{
			if(fseek(m_pFile, iOffset, SEEK_SET))
				throw 1;
		}
		else if(Mode == FSM_CURRENT)
		{
			if(fseek(m_pFile, iOffset, SEEK_CUR))
				throw 1;
		}
		else if(Mode == FSM_END)
		{
			if(fseek(m_pFile, iOffset, SEEK_END))
				throw 1;
		}
		else
		{
			INITIATE_FAILURE;
		}
	}
	else
	{
		if(Mode == FSM_BEGIN)
		{
			if(iOffset < 0 || (size_t)iOffset > m_FilePos.m_szLength)
				INITIATE_FAILURE;

			SetFilePointer(m_hFile, m_FilePos.m_szOffset + iOffset, NULL, FILE_BEGIN); // ... (no error check-up)
		}
		else if(Mode == FSM_CURRENT)
		{
			int iDstOffset = (int)Tell() + iOffset;
			if(iDstOffset < 0 || (size_t)iOffset > m_FilePos.m_szLength)
				INITIATE_FAILURE;

			SetFilePointer(m_hFile, m_FilePos.m_szOffset + iDstOffset, NULL, FILE_BEGIN); // ... (no error check-up)
		}
		else if(Mode == FSM_END)
		{
			int iDstOffset = (int)Tell() + iOffset;
			if(iDstOffset < 0 || (size_t)iOffset > m_FilePos.m_szLength)
				INITIATE_FAILURE;

			SetFilePointer(m_hFile, m_FilePos.m_szOffset + iDstOffset, NULL, FILE_BEGIN); // ... (no error check-up)
		}
		else
		{
			INITIATE_FAILURE;
		}
	}
}
void FPacketCaptureArchive::SerializePacket(void* PacketData, uint32& PacketSize)
{
	check(Header.PacketDataOffset.Get() != 0);
	check(Tell() >= Header.PacketDataOffset.Get());

	uint32 PacketBufferSize = (IsLoading() ? PacketSize : 0);
	uint64 StartPos = Tell();
	InnerArchive << PacketSize;

	if (IsLoading())
	{
		if (Header.CaptureVersion >= CAPTURE_VER_PACKETCOUNT)
		{
			// Added PacketSize here, to deliberately overshoot, in case PacketDataLength is not updated in the file (possible)
			check(Tell() < Header.PacketDataOffset.Get() + Header.PacketDataLength.Get() + (uint32)sizeof(PacketSize) + PacketSize);
		}

		// Max 128MB packet - excessive, but this is not meant to be a perfect security check
		if (PacketBufferSize < PacketSize || !ensure(PacketSize <= 134217728))
		{
			UE_LOG(OodleHandlerComponentLog, Warning, TEXT("Bad PacketSize value '%i' in loading packet capture file"), PacketSize);
			SetError();

			return;
		}

		if (PacketSize > (InnerArchive.TotalSize() - InnerArchive.Tell()))
		{
			UE_LOG(OodleHandlerComponentLog, Warning, TEXT("PacketSize '%i' greater than remaining file data '%i'. Truncated file? ")
					TEXT("(run server with -forcelogflush to reduce chance of truncated capture files)"),
					PacketSize, (InnerArchive.TotalSize() - InnerArchive.Tell()));

			SetError();

			return;
		}
	}

	InnerArchive.Serialize(PacketData, PacketSize);

	if (IsSaving())
	{
		uint32 NewPacketCount = Header.PacketCount.Get() + 1;
		uint32 NewPacketDataLength = Header.PacketDataLength.Get() + (Tell() - StartPos);

		Header.PacketCount.Set(*this, NewPacketCount);
		Header.PacketDataLength.Set(*this, NewPacketDataLength);

		if (bImmediateFlush)
		{
			Flush();
		}
	}
}
Example #20
0
int VSIWin32Handle::Eof()

{
    vsi_l_offset       nCur, nEnd;

    nCur = Tell();
    Seek( 0, SEEK_END );
    nEnd = Tell();
    Seek( nCur, SEEK_SET );

    return (nCur == nEnd);
}
int     FILEFile::GetLength()
{
    int pos = Tell();
    if (pos >= 0)
    {
        Seek (0, Seek_End);
        int size = Tell();
        Seek (pos, Seek_Set);
        return size;
    }
    return -1;
}
Example #22
0
int64 File::FileLength()
{
  
  SaveFilePos SavePos(*this);
  Seek(0,SEEK_END);
  return Tell();
}
Example #23
0
// is end of file reached?
bool wxFile::Eof() const
{
    wxASSERT( IsOpened() );

    wxFileOffset iRc;

#if defined(__DOS__) || defined(__UNIX__) || defined(__GNUWIN32__)
    // @@ this doesn't work, of course, on unseekable file descriptors
    wxFileOffset ofsCur = Tell(),
                 ofsMax = Length();
    if ( ofsCur == wxInvalidOffset || ofsMax == wxInvalidOffset )
        iRc = wxInvalidOffset;
    else
        iRc = ofsCur == ofsMax;
#else  // Windows and "native" compiler
    iRc = wxEof(m_fd);
#endif // Windows/Unix

    if ( iRc == 0 )
        return false;

    if ( iRc == wxInvalidOffset )
    {
        wxLogSysError(_("can't determine if the end of file is reached on descriptor %d"), m_fd);
    }
    else if ( iRc != 1 )
    {
        wxFAIL_MSG(wxT("invalid eof() return value."));
    }

    return true;
}
Example #24
0
size_t Archive::ReadHeader()
{
  // Once we failed to decrypt an encrypted block, there is no reason to
  // attempt to do it further. We'll never be successful and only generate
  // endless errors.
  if (FailedHeaderDecryption)
    return 0;

  CurBlockPos=Tell();

  size_t ReadSize;
  switch(Format)
  {
#ifndef SFX_MODULE
    case RARFMT14:
      ReadSize=ReadHeader14();
      break;
#endif
    case RARFMT15:
      ReadSize=ReadHeader15();
      break;
    case RARFMT50:
      ReadSize=ReadHeader50();
      break;
  }

  if (ReadSize>0 && NextBlockPos<=CurBlockPos)
  {
    BrokenHeaderMsg();
    return 0;
  }
  return ReadSize;
}
Example #25
0
/* internal function for processing an encoding */
static DOH *encode(char *name, DOH *s) {
    DOH *handle, *ns;
    DOH *(*fn) (DOH *);
    long pos;
    char *cfmt = strchr(name, ':');
    DOH *tmp = 0;
    if (cfmt) {
        tmp = NewString(cfmt + 1);
        Append(tmp, s);
        Setfile(tmp, Getfile((DOH *) s));
        Setline(tmp, Getline((DOH *) s));
        *cfmt = '\0';
    }
    if (!encodings || !(handle = Getattr(encodings, name))) {
        return Copy(s);
    }
    if (tmp)
        s = tmp;
    pos = Tell(s);
    Seek(s, 0, SEEK_SET);
    fn = (DOH *(*)(DOH *)) Data(handle);
    ns = (*fn) (s);
    Seek(s, pos, SEEK_SET);
    if (tmp)
        Delete(tmp);
    return ns;
}
FNameTableArchiveWriter::FNameTableArchiveWriter(int32 SerializationVersion, const FString& Filename)
	: FArchive()
	, FileAr(nullptr)
	, FinalFilename(Filename)
	, TempFilename(Filename + TEXT(".tmp"))
{
	ArIsSaving = true;

	// Save to a temp file first, then move to the destination to avoid corruption
	FileAr = IFileManager::Get().CreateFileWriter(*TempFilename, 0);
	if (FileAr)
	{
		int32 MagicNumber = PACKAGE_FILE_TAG;
		*this << MagicNumber;

		int32 VersionToWrite = SerializationVersion;
		*this << VersionToWrite;

		// Just write a 0 for the name table offset for now. This will be overwritten later when we are done serializing
		NameOffsetLoc = Tell();
		int64 NameOffset = 0;
		*this << NameOffset;
	}
	else
	{
		UE_LOG(LogAssetRegistry, Error, TEXT("Failed to open file for write %s"), *Filename);
	}
}
Example #27
0
int VSIVirtualHandle::ReadMultiRange( int nRanges, void ** ppData,
                                      const vsi_l_offset* panOffsets,
                                      const size_t* panSizes )
{
    int nRet = 0;
    vsi_l_offset nCurOffset = Tell();
    for(int i=0;i<nRanges;i++)
    {
        if (Seek(panOffsets[i], SEEK_SET) < 0)
        {
            nRet = -1;
            break;
        }

        size_t nRead = Read(ppData[i], 1, panSizes[i]);
        if (panSizes[i] != nRead)
        {
            nRet = -1;
            break;
        }
    }

    Seek(nCurOffset, SEEK_SET);

    return nRet;
}
Example #28
0
TFile& TFile::Write(const void* pData, size_t szSize)
{
	DEBUG_VERIFY_ALLOCATION;

	DEBUG_VERIFY(IsOpen());

	if(!(m_flOpenFlags & FOF_WRITE) || (m_flOpenFlags & FOF_TEXT))
		INITIATE_FAILURE;

	size_t szCurrentOffset = Tell();
	if(	(szCurrentOffset + szSize > m_FilePos.m_szLength) &&
		!(m_flOpenFlags & FOF_RESIZE))
	{
		INITIATE_FAILURE;
	}

	DWORD dwRealSize;
	if(!WriteFile(m_hFile, pData, szSize, &dwRealSize, NULL) || dwRealSize != szSize)
		INITIATE_FAILURE;

	size_t szLastOffset = szCurrentOffset + szSize;
	if(szLastOffset > m_FilePos.m_szLength)
		m_FilePos.m_szLength = szLastOffset;

	return *this;
}
Example #29
0
        bool File::Seek(long pos, FileSeek mode)
        {
            switch (mode)
            {
                case FileSeek::Set:
                {
                    fseek(m_handle, pos, SEEK_SET);
                } break;

                case FileSeek::Current:
                {
                    fseek(m_handle, pos, SEEK_CUR);
                } break;

                case FileSeek::End:
                {
                    fseek(m_handle, pos, SEEK_END);
                } break;
            }

            m_position = Tell();

            int err = errno;
            if (err > 0) {
                throw FileException(m_path, err);
                return false;
            }

            return true;
        }
Example #30
0
int cFile::ReadRestOfFile(AString & a_Contents)
{
	ASSERT(IsOpen());

	if (!IsOpen())
	{
		return -1;
	}

	long TotalSize = GetSize();
	if (TotalSize < 0)
	{
		return -1;
	}

	long Position = Tell();
	if (Position < 0)
	{
		return -1;
	}

	auto DataSize = static_cast<size_t>(TotalSize - Position);

	// HACK: This depends on the internal knowledge that AString's data() function returns the internal buffer directly
	a_Contents.assign(DataSize, '\0');
	return Read(reinterpret_cast<void *>(const_cast<char *>(a_Contents.data())), DataSize);
}