summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/File.cpp
diff options
context:
space:
mode:
authortycho <work.tycho@gmail.com>2015-05-19 12:50:59 +0200
committertycho <work.tycho@gmail.com>2015-05-19 12:50:59 +0200
commitf2689c4887e6bd66af34de81cd793322f1dd57c4 (patch)
treeb8b78c3f7715797a640dc77b4474e1d2fe347e0c /src/OSSupport/File.cpp
parentMerge branch 'master' of https://github.com/mc-server/MCServer (diff)
downloadcuberite-f2689c4887e6bd66af34de81cd793322f1dd57c4.tar
cuberite-f2689c4887e6bd66af34de81cd793322f1dd57c4.tar.gz
cuberite-f2689c4887e6bd66af34de81cd793322f1dd57c4.tar.bz2
cuberite-f2689c4887e6bd66af34de81cd793322f1dd57c4.tar.lz
cuberite-f2689c4887e6bd66af34de81cd793322f1dd57c4.tar.xz
cuberite-f2689c4887e6bd66af34de81cd793322f1dd57c4.tar.zst
cuberite-f2689c4887e6bd66af34de81cd793322f1dd57c4.zip
Diffstat (limited to 'src/OSSupport/File.cpp')
-rw-r--r--src/OSSupport/File.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/OSSupport/File.cpp b/src/OSSupport/File.cpp
index 43105b230..53f7c4afe 100644
--- a/src/OSSupport/File.cpp
+++ b/src/OSSupport/File.cpp
@@ -201,7 +201,7 @@ int cFile::Seek (int iPosition)
-int cFile::Tell (void) const
+ssize_t cFile::Tell (void) const
{
ASSERT(IsOpen());
@@ -210,14 +210,14 @@ int cFile::Tell (void) const
return -1;
}
- return (int)ftell(m_File);
+ return ftell(m_File);
}
-int cFile::GetSize(void) const
+ssize_t cFile::GetSize(void) const
{
ASSERT(IsOpen());
@@ -226,7 +226,7 @@ int cFile::GetSize(void) const
return -1;
}
- int CurPos = Tell();
+ ssize_t CurPos = Tell();
if (CurPos < 0)
{
return -1;
@@ -235,7 +235,7 @@ int cFile::GetSize(void) const
{
return -1;
}
- int res = Tell();
+ ssize_t res = Tell();
if (fseek(m_File, (long)CurPos, SEEK_SET) != 0)
{
return -1;
@@ -256,7 +256,19 @@ int cFile::ReadRestOfFile(AString & a_Contents)
return -1;
}
- size_t DataSize = GetSize() - Tell();
+ ssize_t TotalSize = GetSize();
+ if (TotalSize < 0)
+ {
+ return -1;
+ }
+
+ ssize_t Position = Tell();
+ if (Position < 0)
+ {
+ return -1;
+ }
+
+ auto DataSize = static_cast<size_t>(TotalSize - Position);
// HACK: This depends on the internal knowledge that AString's data() function returns the internal buffer directly
a_Contents.assign(DataSize, '\0');
@@ -349,7 +361,7 @@ bool cFile::IsFile(const AString & a_Path)
-int cFile::GetSize(const AString & a_FileName)
+ssize_t cFile::GetSize(const AString & a_FileName)
{
struct stat st;
if (stat(a_FileName.c_str(), &st) == 0)