Core/Posix: Fix file opening in ReadWrite mode

Former-commit-id: 7c4a5d3e31e9449fa3c23cfad58523ed54b7834a
This commit is contained in:
Lynix 2015-11-30 12:50:56 +01:00
parent 840c591b6e
commit 5e8f8549af
1 changed files with 11 additions and 21 deletions

View File

@ -18,8 +18,8 @@ namespace Nz
void FileImpl::Close() void FileImpl::Close()
{ {
if (m_fileDescriptor != -1) if (m_fileDescriptor != -1)
close(m_fileDescriptor); close(m_fileDescriptor);
} }
bool FileImpl::EndOfFile() const bool FileImpl::EndOfFile() const
@ -54,30 +54,20 @@ namespace Nz
int flags; int flags;
mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
if (mode & OpenMode_ReadOnly) if (mode & OpenMode_ReadWrite)
flags = O_RDONLY;
else if (mode & OpenMode_ReadWrite)
{
flags = O_CREAT | O_RDWR; flags = O_CREAT | O_RDWR;
else if (mode & OpenMode_ReadOnly)
if (mode & OpenMode_Append) flags = O_RDONLY;
flags |= O_APPEND;
if (mode & OpenMode_Truncate)
flags |= O_TRUNC;
}
else if (mode & OpenMode_WriteOnly) else if (mode & OpenMode_WriteOnly)
{
flags = O_CREAT | O_WRONLY; flags = O_CREAT | O_WRONLY;
if (mode & OpenMode_Append)
flags |= O_APPEND;
if (mode & OpenMode_Truncate)
flags |= O_TRUNC;
}
else else
return false; return false;
if (mode & OpenMode_Append)
flags |= O_APPEND;
if (mode & OpenMode_Truncate)
flags |= O_TRUNC;
///TODO: lock ///TODO: lock
// if ((mode & OpenMode_Lock) == 0) // if ((mode & OpenMode_Lock) == 0)