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