From f322f1d7e7ada7f8013c56fefaafdfb902f135f7 Mon Sep 17 00:00:00 2001 From: Antidote Date: Sun, 28 Dec 2014 14:38:55 -0800 Subject: [PATCH] * Change Athena::utility::fileSize to use stat64 instead of ftello * Fix output of ftello64 in win32_largefilewrapper --- include/Athena/Utility.hpp | 2 +- include/win32_largefilewrapper.h | 2 +- src/Athena/FileReader.cpp | 2 +- src/Athena/FileWriter.cpp | 2 +- src/Athena/Utility.cpp | 11 +++++------ src/win32_largefilewrapper.c | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/Athena/Utility.hpp b/include/Athena/Utility.hpp index c418235..bbe34c0 100644 --- a/include/Athena/Utility.hpp +++ b/include/Athena/Utility.hpp @@ -74,7 +74,7 @@ std::string &rtrim(std::string &s); // trim from both ends std::string &trim(std::string &s); -atUint64 fileSize(FILE* f); +atUint64 fileSize(const std::string& filename); } // utility } // Athena #endif diff --git a/include/win32_largefilewrapper.h b/include/win32_largefilewrapper.h index 75f81a8..054c504 100644 --- a/include/win32_largefilewrapper.h +++ b/include/win32_largefilewrapper.h @@ -7,7 +7,7 @@ extern "C" { #endif int fseeko64(FILE* fp, off64_t offset, int whence); -int ftello64(FILE* fp); +off64_t ftello64(FILE* fp); #ifdef __cplusplus } #endif diff --git a/src/Athena/FileReader.cpp b/src/Athena/FileReader.cpp index 5c4dc82..c5c6437 100644 --- a/src/Athena/FileReader.cpp +++ b/src/Athena/FileReader.cpp @@ -119,7 +119,7 @@ atUint64 FileReader::length() const if (!isOpen()) THROW_INVALID_OPERATION_EXCEPTION("File not open"); - return utility::fileSize(m_fileHandle); + return utility::fileSize(m_filename); } void FileReader::seekBit(int bit) diff --git a/src/Athena/FileWriter.cpp b/src/Athena/FileWriter.cpp index fd01b6f..d848a36 100644 --- a/src/Athena/FileWriter.cpp +++ b/src/Athena/FileWriter.cpp @@ -109,7 +109,7 @@ atUint64 FileWriter::position() const atUint64 FileWriter::length() const { - return utility::fileSize(m_fileHandle); + return utility::fileSize(m_filename); } void FileWriter::writeBit(bool val) diff --git a/src/Athena/Utility.cpp b/src/Athena/Utility.cpp index 516a2be..a040121 100644 --- a/src/Athena/Utility.cpp +++ b/src/Athena/Utility.cpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace Athena { @@ -365,13 +366,11 @@ int countChar(const std::string& str, const char chr, int* lastOccur) return ret; } -atUint64 fileSize(FILE* f) +atUint64 fileSize(const std::string& filename) { - atUint64 oldPos = ftello64(f); - fseeko64(f, 0, SEEK_END); - atUint64 size = ftello64(f); - fseeko64(f, oldPos, SEEK_SET); - return size; + struct stat64 st; + stat64(filename.c_str(), &st); + return st.st_size; } std::string& ltrim(std::string& s) diff --git a/src/win32_largefilewrapper.c b/src/win32_largefilewrapper.c index b18e306..75da284 100644 --- a/src/win32_largefilewrapper.c +++ b/src/win32_largefilewrapper.c @@ -7,7 +7,7 @@ int fseeko64(FILE* fp, off64_t offset, int whence) return _fseeki64(fp, offset, whence); } -int ftello64(FILE* fp) +off64_t ftello64(FILE* fp) { return _ftelli64(fp); }