From f4583fda98b578966969db7d94a0bae3c87b0c80 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 30 Jan 2012 22:48:38 +0000 Subject: Replaced most FILE operations with a cFile object git-svn-id: http://mc-server.googlecode.com/svn/trunk@196 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cFile.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'source/cFile.cpp') diff --git a/source/cFile.cpp b/source/cFile.cpp index 84308984a..caaef010a 100644 --- a/source/cFile.cpp +++ b/source/cFile.cpp @@ -198,3 +198,34 @@ int cFile::Tell (void) const + +/// Returns the size of file, in bytes, or -1 for failure; asserts if not open +int cFile::GetSize(void) const +{ + assert(IsOpen()); + + if (!IsOpen()) + { + return -1; + } + + int CurPos = ftell(m_File); + if (CurPos < 0) + { + return -1; + } + if (fseek(m_File, 0, SEEK_END) != 0) + { + return -1; + } + int res = ftell(m_File); + if (fseek(m_File, CurPos, SEEK_SET) != 0) + { + return -1; + } + return res; +} + + + + -- cgit v1.2.3