libept
|
Common operations on file descriptors. More...
#include <sys.h>
Public Member Functions | |
FileDescriptor () | |
FileDescriptor (FileDescriptor &&o) | |
FileDescriptor (int fd) | |
virtual | ~FileDescriptor () |
virtual void | throw_error (const char *desc) |
Throw an exception based on errno and the given message. More... | |
void | close () |
void | fstat (struct stat &st) |
void | fchmod (mode_t mode) |
size_t | write (const void *buf, size_t count) |
void | write_all (const void *buf, size_t count) |
Write all the data in buf, retrying partial writes. More... | |
MMap | mmap (size_t length, int prot, int flags, off_t offset=0) |
operator int () const | |
Protected Attributes | |
int | fd = -1 |
Common operations on file descriptors.
Except when documented otherwise, methods of this class are just thin wrappers around the libc functions with the same name, that check error results and throw exceptions if the functions failed.
Implementing what to do on construction and destruction is left to the subclassers: at the FileDescriptor level, the destructor does nothing and leaves the file descriptor open.
ept::sys::FileDescriptor::FileDescriptor | ( | ) |
ept::sys::FileDescriptor::FileDescriptor | ( | FileDescriptor && | o | ) |
ept::sys::FileDescriptor::FileDescriptor | ( | int | fd | ) |
|
virtual |
void ept::sys::FileDescriptor::close | ( | ) |
References fd, and throw_error().
Referenced by ept::sys::write_file(), ept::sys::write_file_atomically(), ept::sys::File::~File(), and ept::sys::Path::~Path().
void ept::sys::FileDescriptor::fchmod | ( | mode_t | mode | ) |
References fd, and throw_error().
Referenced by ept::sys::write_file_atomically().
void ept::sys::FileDescriptor::fstat | ( | struct stat & | st | ) |
References fd, and throw_error().
Referenced by ept::sys::read_file().
MMap ept::sys::FileDescriptor::mmap | ( | size_t | length, |
int | prot, | ||
int | flags, | ||
off_t | offset = 0 |
||
) |
References fd, res, and throw_error().
Referenced by ept::sys::read_file().
|
inline |
|
virtual |
Throw an exception based on errno and the given message.
This can be overridden by subclasses that may have more information about the file descriptor, so that they can generate more descriptive messages.
Reimplemented in ept::sys::NamedFileDescriptor.
Referenced by close(), fchmod(), fstat(), mmap(), and write().
size_t ept::sys::FileDescriptor::write | ( | const void * | buf, |
size_t | count | ||
) |
References fd, res, and throw_error().
Referenced by write_all().
void ept::sys::FileDescriptor::write_all | ( | const void * | buf, |
size_t | count | ||
) |
Write all the data in buf, retrying partial writes.
References write().
Referenced by ept::sys::write_file(), and ept::sys::write_file_atomically().
|
protected |
Referenced by ept::sys::Path::begin(), close(), fchmod(), ept::sys::Path::fdopendir(), ept::sys::File::File(), fstat(), ept::sys::Path::fstatat(), ept::sys::Path::iterator::iterator(), ept::sys::Path::lstatat(), ept::sys::File::mkstemp(), mmap(), ept::sys::Path::openat(), ept::sys::NamedFileDescriptor::operator=(), ept::sys::Path::Path(), ept::sys::Path::rmdirat(), ept::sys::Path::unlinkat(), write(), ept::sys::File::~File(), and ept::sys::Path::~Path().