1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 14:25:08 +00:00

LibCore: Move GIODevice hierarchy from LibGUI to LibCore.

This commit is contained in:
Andreas Kling 2019-04-10 20:22:23 +02:00
parent fc1d3074de
commit cfd6e6cc36
19 changed files with 112 additions and 112 deletions

42
LibCore/CFile.cpp Normal file
View file

@ -0,0 +1,42 @@
#include <LibCore/CFile.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
CFile::CFile(const String& filename)
: m_filename(filename)
{
}
CFile::~CFile()
{
if (mode() != NotOpen)
close();
}
bool CFile::open(CIODevice::OpenMode mode)
{
int flags = 0;
if ((mode & CIODevice::ReadWrite) == CIODevice::ReadWrite) {
flags |= O_RDWR | O_CREAT;
} else if (mode & CIODevice::ReadOnly) {
flags |= O_RDONLY;
} else if (mode & CIODevice::WriteOnly) {
flags |= O_WRONLY | O_CREAT;
}
if (mode & CIODevice::Append)
flags |= O_APPEND;
if (mode & CIODevice::Truncate)
flags |= O_TRUNC;
if (mode & CIODevice::MustBeNew)
flags |= O_EXCL;
int fd = ::open(m_filename.characters(), flags, 0666);
if (fd < 0) {
set_error(errno);
return false;
}
set_fd(fd);
set_mode(mode);
return true;
}