diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-04-23 23:20:32 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-04-23 23:20:32 +0200 |
commit | 9cb88728511c314695731d92cb4ab16c8e3b051e (patch) | |
tree | 6503c19dec45a7dc39377de39a1ff625ea321fbf /source/cFile.cpp | |
parent | Lapis gets generated (thanks, Fordship) (diff) | |
download | cuberite-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.cpp | 20 |
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();
+}
+
+
+
+
|