diff options
| author | Shawn Hoffman <godisgovernment@gmail.com> | 2010-12-03 12:42:01 +0000 |
|---|---|---|
| committer | Shawn Hoffman <godisgovernment@gmail.com> | 2010-12-03 12:42:01 +0000 |
| commit | 3d441febda6a22a6e35168f5f5f4218275cf8295 (patch) | |
| tree | 1e181d6738bc9897fcd17d85ab51c4154f0eaa5d /Source/Core/Common/Src/FileUtil.cpp | |
| parent | 08a3b60f8c52a88de31070e1cb4f8e5dadab47e8 (diff) | |
Attempt to fix issue r3458. I don't have a 32bit linux install, however I know it will at least fix compressing. Please test if uncompressed games run.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6510 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/Common/Src/FileUtil.cpp')
| -rw-r--r-- | Source/Core/Common/Src/FileUtil.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index bf57fbdd1c..d1c49cb067 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -345,6 +345,24 @@ u64 GetSize(const char *filename) return 0; } +// Overloaded GetSize, accepts file descriptor +u64 GetSize(const int fd) +{ + struct stat64 buf; + if (fstat64(fd, &buf) != 0) { + ERROR_LOG(COMMON, "GetSize: stat failed %i: %s", + fd, GetLastErrorMsg()); + return 0; + } + return buf.st_size; +} + +// Overloaded GetSize, accepts FILE* +u64 GetSize(FILE *f) +{ + return GetSize(fileno(f)); +} + // creates an empty file filename, returns true on success bool CreateEmptyFile(const char *filename) { @@ -769,9 +787,7 @@ bool ReadFileToString(bool text_file, const char *filename, std::string &str) FILE *f = fopen(filename, text_file ? "r" : "rb"); if (!f) return false; - fseek(f, 0, SEEK_END); - size_t len = (size_t)ftell(f); - fseek(f, 0, SEEK_SET); + size_t len = (size_t)GetSize(f); char *buf = new char[len + 1]; buf[fread(buf, 1, len, f)] = 0; str = std::string(buf, len); |
