summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authornakeee <nakeee@gmail.com>2008-11-30 11:19:05 +0000
committernakeee <nakeee@gmail.com>2008-11-30 11:19:05 +0000
commitcf2468ec4d6eff4973f08710337c765367464cbf (patch)
tree0587158fc2cda3b341388a56d9a925f161c5634e /Source
parent2f528a3de4863b312e13cef32fefd9d5f27b1c39 (diff)
linux fixes
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1335 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Common/Src/FileUtil.cpp49
-rw-r--r--Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp22
2 files changed, 60 insertions, 11 deletions
diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp
index 68d333eb7a..8342c0baed 100644
--- a/Source/Core/Common/Src/FileUtil.cpp
+++ b/Source/Core/Common/Src/FileUtil.cpp
@@ -32,6 +32,9 @@
#include <stdlib.h>
#endif
+#include <fstream>
+
+
namespace File
{
@@ -221,6 +224,52 @@ bool Copy(const char *srcFilename, const char *destFilename)
return CopyFile(srcFilename, destFilename, FALSE);
#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
}
diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp
index 8c6f08cc51..1de4ad678e 100644
--- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp
+++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp
@@ -104,16 +104,13 @@ CWII_IPC_HLE_Device_FileIO::Open(u32 _CommandAddress, u32 _Mode)
if (m_pFileHandle != NULL)
{
- fseek(m_pFileHandle, 0, SEEK_END);
- m_FileLength = (u32)ftell(m_pFileHandle);
- rewind(m_pFileHandle);
-
- ReturnValue = GetDeviceID();
+ m_FileLength = File::GetSize(m_Filename.c_str());
+ ReturnValue = GetDeviceID();
}
else
{
- LOG(WII_IPC_FILEIO, " failed - File doesn't exist");
- ReturnValue = -106;
+ LOG(WII_IPC_FILEIO, " failed - File doesn't exist");
+ ReturnValue = -106;
}
Memory::Write_U32(ReturnValue, _CommandAddress+4);
@@ -133,9 +130,12 @@ CWII_IPC_HLE_Device_FileIO::Seek(u32 _CommandAddress)
switch(Mode)
{
case 0:
- fseek(m_pFileHandle, SeekPosition, SEEK_SET);
+ if (fseek(m_pFileHandle, SeekPosition, SEEK_SET) == 0) {
// Seek always return the seek position for success
ReturnValue = SeekPosition;
+ } else {
+ LOG(WII_IPC_FILEIO, "FILEIO: Seek failed");
+ }
break;
case 1: // cur
@@ -212,8 +212,8 @@ CWII_IPC_HLE_Device_FileIO::IOCtl(u32 _CommandAddress)
{
case ISFS_IOCTL_GETFILESTATS:
{
- u32 Position = (u32)ftell(m_pFileHandle);
-
+ u32 Position = (u32)ftell(m_pFileHandle);
+
u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18);
LOG(WII_IPC_FILEIO, "FileIO: ISFS_IOCTL_GETFILESTATS");
LOG(WII_IPC_FILEIO, " Length: %i Seek: %i", m_FileLength, Position);
@@ -245,4 +245,4 @@ CWII_IPC_HLE_Device_FileIO::ReturnFileHandle()
return false;
else
return true;
-} \ No newline at end of file
+}