mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:38:11 +00:00
Libraries: Create top level directory for libraries.
Things were getting a little crowded in the project root, so this patch moves the Lib*/ directories into Libraries/.
This commit is contained in:
parent
63814ffebf
commit
04b9dc2d30
328 changed files with 36 additions and 36 deletions
51
Libraries/LibCore/CFile.cpp
Normal file
51
Libraries/LibCore/CFile.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include <LibCore/CFile.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
CFile::CFile(const StringView& filename)
|
||||
: m_filename(filename)
|
||||
{
|
||||
}
|
||||
|
||||
CFile::~CFile()
|
||||
{
|
||||
if (m_should_close_file_descriptor == ShouldCloseFileDescription::Yes && mode() != NotOpen)
|
||||
close();
|
||||
}
|
||||
|
||||
bool CFile::open(int fd, CIODevice::OpenMode mode, ShouldCloseFileDescription should_close)
|
||||
{
|
||||
set_fd(fd);
|
||||
set_mode(mode);
|
||||
m_should_close_file_descriptor = should_close;
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue