30 #ifndef FILE_DESCRIPTOR_HXX 31 #define FILE_DESCRIPTOR_HXX 38 #include <sys/types.h> 58 return fd == other.
fd;
69 constexpr
int Get()
const {
73 void Set(
int _fd) noexcept {
93 bool Open(
const char *pathname,
int flags, mode_t mode=0666) noexcept;
115 return ::dup2(
Get(), new_fd) == 0;
120 bool CreateEventFD(
unsigned initval=0) noexcept;
124 bool CreateSignalFD(
const sigset_t *mask) noexcept;
127 #ifdef HAVE_INOTIFY_INIT 128 bool CreateInotify() noexcept;
137 return ::close(
Steal()) == 0;
145 off_t
Seek(off_t offset) noexcept {
146 return lseek(
Get(), offset, SEEK_SET);
149 off_t
Skip(off_t offset) noexcept {
150 return lseek(
Get(), offset, SEEK_CUR);
155 return lseek(
Get(), 0, SEEK_CUR);
162 off_t
GetSize() const noexcept;
164 ssize_t
Read(
void *buffer,
size_t length) noexcept {
165 return ::read(
fd, buffer, length);
168 ssize_t
Write(
const void *buffer,
size_t length) noexcept {
169 return ::write(
fd, buffer, length);
173 int Poll(
short events,
int timeout)
const noexcept;
gcc_pure off_t Tell() const noexcept
void Set(int _fd) noexcept
constexpr FileDescriptor(int _fd)
gcc_pure off_t GetSize() const noexcept
Returns the size of the file in bytes, or -1 on error.
static bool CreatePipe(FileDescriptor &r, FileDescriptor &w) noexcept
off_t Skip(off_t offset) noexcept
void SetUndefined() noexcept
off_t Seek(off_t offset) noexcept
int Poll(short events, int timeout) const noexcept
bool Close() noexcept
Close the file descriptor.
int WaitReadable(int timeout) const noexcept
bool OpenReadOnly(const char *pathname) noexcept
ssize_t Write(const void *buffer, size_t length) noexcept
constexpr bool IsDefined() const
bool Rewind() noexcept
Rewind the pointer to the beginning of the file.
bool OpenNonBlocking(const char *pathname) noexcept
bool Open(const char *pathname, int flags, mode_t mode=0666) noexcept
bool Duplicate(int new_fd) const noexcept
Duplicate the file descriptor onto the given file descriptor.
int WaitWritable(int timeout) const noexcept
static constexpr FileDescriptor Undefined()
constexpr bool operator==(FileDescriptor other) const
An OO wrapper for a UNIX file descriptor.
void SetNonBlocking() noexcept
Enable non-blocking mode on this file descriptor.
void SetBlocking() noexcept
Enable blocking mode on this file descriptor.
ssize_t Read(void *buffer, size_t length) noexcept
constexpr int Get() const
Returns the file descriptor.