summaryrefslogtreecommitdiffstats
path: root/source/cFile.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-04-23 23:20:32 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-04-23 23:20:32 +0200
commit9cb88728511c314695731d92cb4ab16c8e3b051e (patch)
tree6503c19dec45a7dc39377de39a1ff625ea321fbf /source/cFile.cpp
parentLapis gets generated (thanks, Fordship) (diff)
downloadcuberite-9cb88728511c314695731d92cb4ab16c8e3b051e.tar
cuberite-9cb88728511c314695731d92cb4ab16c8e3b051e.tar.gz
cuberite-9cb88728511c314695731d92cb4ab16c8e3b051e.tar.bz2
cuberite-9cb88728511c314695731d92cb4ab16c8e3b051e.tar.lz
cuberite-9cb88728511c314695731d92cb4ab16c8e3b051e.tar.xz
cuberite-9cb88728511c314695731d92cb4ab16c8e3b051e.tar.zst
cuberite-9cb88728511c314695731d92cb4ab16c8e3b051e.zip
Diffstat (limited to 'source/cFile.cpp')
-rw-r--r--source/cFile.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/source/cFile.cpp b/source/cFile.cpp
index 5ea71107a..cd61800e2 100644
--- a/source/cFile.cpp
+++ b/source/cFile.cpp
@@ -69,7 +69,7 @@ bool cFile::Open(const AString & iFileName, EMode iMode)
{
case fmRead: Mode = "rb"; break;
case fmWrite: Mode = "wb"; break;
- case fmReadWrite: Mode = "ab+"; break;
+ case fmReadWrite: Mode = "rb+"; break;
default:
{
ASSERT(!"Unhandled file mode");
@@ -77,6 +77,14 @@ bool cFile::Open(const AString & iFileName, EMode iMode)
}
}
m_File = fopen(iFileName.c_str(), Mode);
+ if ((m_File == NULL) && (iMode == fmReadWrite))
+ {
+ // Fix for MS not following C spec, opening "a" mode files for writing at the end only
+ // The file open operation has been tried with "read update", fails if file not found
+ // So now we know either the file doesn't exist or we don't have rights, no need to worry about file contents.
+ // Simply re-open for read-writing, erasing existing contents:
+ m_File = fopen(iFileName.c_str(), "wb+");
+ }
return (m_File != NULL);
}
@@ -251,3 +259,13 @@ int cFile::ReadRestOfFile(AString & a_Contents)
+
+bool cFile::Exists(const AString & a_FileName)
+{
+ cFile test(a_FileName, fmRead);
+ return test.IsOpen();
+}
+
+
+
+