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