From 3d441febda6a22a6e35168f5f5f4218275cf8295 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Fri, 3 Dec 2010 12:42:01 +0000 Subject: 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 --- Source/Core/Common/Src/FileUtil.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'Source/Core/Common/Src/FileUtil.cpp') 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); -- cgit v1.2.3