ISFS_Seek: Turns out POSIX allows seek past EOF, the Wii does not.

Should fix Issue 3761 (really!), please test this.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6723 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
j4ck.fr0st 2011-01-02 12:27:33 +00:00
parent 75a8fa7340
commit 638fa77954
1 changed files with 19 additions and 11 deletions

View File

@ -148,20 +148,28 @@ bool CWII_IPC_HLE_Device_FileIO::Seek(u32 _CommandAddress)
u32 ReturnValue = FS_INVALID_ARGUMENT;
s32 SeekPosition = Memory::Read_U32(_CommandAddress + 0xC);
s32 Mode = Memory::Read_U32(_CommandAddress + 0x10);
u64 fileSize = File::GetSize(m_pFileHandle);
INFO_LOG(WII_IPC_FILEIO, "FileIO: Seek Pos: 0x%08x, Mode: %i (%s, Length=0x%08llx)", SeekPosition, Mode, m_Name.c_str(), File::GetSize(m_pFileHandle));
/* TODO: Check if the new changes and the removed hack
"magically" fixes Zelda - Twilight Princess as well */
INFO_LOG(WII_IPC_FILEIO, "FileIO: Seek Pos: 0x%08x, Mode: %i (%s, Length=0x%08llx)", SeekPosition, Mode, m_Name.c_str(), fileSize);
// Set seek mode
int seek_mode[3] = {SEEK_SET, SEEK_CUR, SEEK_END};
if (Mode >= 0 && Mode <= 2)
{
// POSIX allows seek past EOF, the Wii does not.
// TODO: Can we check this without tell'ing/seek'ing twice?
u64 curPos = ftello(m_pFileHandle);
if (fseeko(m_pFileHandle, SeekPosition, seek_mode[Mode]) == 0)
{
ReturnValue = (u32)ftello(m_pFileHandle);
u64 newPos = ftello(m_pFileHandle);
if (newPos > fileSize)
{
ERROR_LOG(WII_IPC_FILEIO, "FILEIO: Seek past EOF - %s", m_Name.c_str());
fseeko(m_pFileHandle, curPos, SEEK_SET);
}
else
ReturnValue = (u32)newPos;
}
else
{