summaryrefslogtreecommitdiffstats
path: root/source/cFile.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-30 23:48:38 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-30 23:48:38 +0100
commitf4583fda98b578966969db7d94a0bae3c87b0c80 (patch)
tree7edca3f33014046fa95a330a8809497d4fa52e3d /source/cFile.cpp
parentFixed a problem in cCSLock (sorry); reverted cChunk (diff)
downloadcuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.tar
cuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.tar.gz
cuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.tar.bz2
cuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.tar.lz
cuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.tar.xz
cuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.tar.zst
cuberite-f4583fda98b578966969db7d94a0bae3c87b0c80.zip
Diffstat (limited to '')
-rw-r--r--source/cFile.cpp31
1 files changed, 31 insertions, 0 deletions
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;
+}
+
+
+
+