Better seeking for IsoFile; using s64 to allow for a full 4gb of addressable file positions in either direction.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2166 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2009-11-08 17:46:56 +00:00
parent c6b14bd7f0
commit b562e8aa0f
2 changed files with 9 additions and 7 deletions

View File

@ -59,21 +59,23 @@ u32 IsoFile::seek(u32 absoffset)
return currentOffset;
}
u32 IsoFile::seek(s32 offset, wxSeekMode ref_position)
// Returns the new offset in the file. Out-of-bounds seeks are automatically truncated at 0
// and fileLength.
u32 IsoFile::seek(s64 offset, wxSeekMode ref_position)
{
switch( ref_position )
{
case wxFromStart:
pxAssertDev( offset > 0, "Invalid seek position from start." );
pxAssertDev( offset >= 0 && offset <= (s64)ULONG_MAX, "Invalid seek position from start." );
return seek(offset);
case wxFromCurrent:
// truncate negative values to zero
return seek( std::max<u32>(0, currentOffset+offset) );
// truncate negative values to zero, and positive values to 4gb
return seek( std::min( std::max<s64>(0, (s64)currentOffset+offset), (s64)ULONG_MAX ) );
case wxFromEnd:
// truncate negative values to zero
return seek( std::max<u32>(0, fileEntry.size+offset) );
// truncate negative values to zero, and positive values to 4gb
return seek( std::min( std::max<s64>(0, (s64)fileEntry.size+offset), (s64)ULONG_MAX ) );
jNO_DEFAULT;
}

View File

@ -26,7 +26,7 @@ public:
virtual ~IsoFile() throw();
u32 seek(u32 absoffset);
u32 seek(s32 offset, wxSeekMode ref_position);
u32 seek(s64 offset, wxSeekMode ref_position);
void reset();
s32 skip(s32 n);