mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
8e3d0a23d5
And use these to do the line-by-line reading automagically instead of having that logic in IRCClient. This will definitely come in handy.
43 lines
916 B
C++
43 lines
916 B
C++
#include <LibGUI/GFile.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
|
|
GFile::GFile(const String& filename)
|
|
: m_filename(filename)
|
|
{
|
|
}
|
|
|
|
GFile::~GFile()
|
|
{
|
|
if (mode() != NotOpen)
|
|
close();
|
|
}
|
|
|
|
bool GFile::open(GIODevice::OpenMode mode)
|
|
{
|
|
int flags = 0;
|
|
if ((mode & GIODevice::ReadWrite) == GIODevice::ReadWrite) {
|
|
flags |= O_RDWR | O_CREAT;
|
|
} else if (mode & GIODevice::ReadOnly) {
|
|
flags |= O_RDONLY;
|
|
} else if (mode & GIODevice::WriteOnly) {
|
|
flags |= O_WRONLY | O_CREAT;
|
|
}
|
|
if (mode & GIODevice::Append)
|
|
flags |= O_APPEND;
|
|
if (mode & GIODevice::Truncate)
|
|
flags |= O_TRUNC;
|
|
if (mode & GIODevice::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;
|
|
}
|