linux fixes

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1335 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nakeee 2008-11-30 11:19:05 +00:00
parent 2f528a3de4
commit cf2468ec4d
2 changed files with 60 additions and 11 deletions

View File

@ -32,6 +32,9 @@
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#include <fstream>
namespace File namespace File
{ {
@ -221,6 +224,52 @@ bool Copy(const char *srcFilename, const char *destFilename)
return CopyFile(srcFilename, destFilename, FALSE); return CopyFile(srcFilename, destFilename, FALSE);
#else #else
#define BSIZE 1024
int rnum, wnum, err;
char buffer[BSIZE];
FILE *output, *input;
if (! (input = fopen(srcFilename, "r"))) {
err = errno;
PanicAlert("Error copying from %s: %s", srcFilename, strerror(err));
return false;
}
if (! (output = fopen(destFilename, "w"))) {
err = errno;
PanicAlert("Error copying to %s: %s", destFilename, strerror(err));
return false;
}
while(! feof(input)) {
if((rnum = fread(buffer, sizeof(char), BSIZE, input)) != BSIZE) {
if(ferror(input) != 0){
PanicAlert("can't read source file\n");
return false;
}
}
if((wnum = fwrite(buffer, sizeof(char), rnum, output))!= rnum){
PanicAlert("can't write output file\n");
return false;
}
}
fclose(input);
fclose(output);
return true;
/*
std::ifstream ifs(srcFilename, std::ios::binary);
std::ofstream ofs(destFilename, std::ios::binary);
ofs << ifs.rdbuf();
ifs.close();
ofs.close();
return true;*/
#endif #endif
} }

View File

@ -104,16 +104,13 @@ CWII_IPC_HLE_Device_FileIO::Open(u32 _CommandAddress, u32 _Mode)
if (m_pFileHandle != NULL) if (m_pFileHandle != NULL)
{ {
fseek(m_pFileHandle, 0, SEEK_END); m_FileLength = File::GetSize(m_Filename.c_str());
m_FileLength = (u32)ftell(m_pFileHandle); ReturnValue = GetDeviceID();
rewind(m_pFileHandle);
ReturnValue = GetDeviceID();
} }
else else
{ {
LOG(WII_IPC_FILEIO, " failed - File doesn't exist"); LOG(WII_IPC_FILEIO, " failed - File doesn't exist");
ReturnValue = -106; ReturnValue = -106;
} }
Memory::Write_U32(ReturnValue, _CommandAddress+4); Memory::Write_U32(ReturnValue, _CommandAddress+4);
@ -133,9 +130,12 @@ CWII_IPC_HLE_Device_FileIO::Seek(u32 _CommandAddress)
switch(Mode) switch(Mode)
{ {
case 0: case 0:
fseek(m_pFileHandle, SeekPosition, SEEK_SET); if (fseek(m_pFileHandle, SeekPosition, SEEK_SET) == 0) {
// Seek always return the seek position for success // Seek always return the seek position for success
ReturnValue = SeekPosition; ReturnValue = SeekPosition;
} else {
LOG(WII_IPC_FILEIO, "FILEIO: Seek failed");
}
break; break;
case 1: // cur case 1: // cur
@ -212,7 +212,7 @@ CWII_IPC_HLE_Device_FileIO::IOCtl(u32 _CommandAddress)
{ {
case ISFS_IOCTL_GETFILESTATS: case ISFS_IOCTL_GETFILESTATS:
{ {
u32 Position = (u32)ftell(m_pFileHandle); u32 Position = (u32)ftell(m_pFileHandle);
u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18); u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18);
LOG(WII_IPC_FILEIO, "FileIO: ISFS_IOCTL_GETFILESTATS"); LOG(WII_IPC_FILEIO, "FileIO: ISFS_IOCTL_GETFILESTATS");