58 inline void munmap(
const memory_region& region)
60 ::munmap(region.address, region.length);
64#if (__cplusplus >= 201709L)
68 typedef w::handle<memory_region, memory_region { }, detail::munmap> mmap_handle;
91 template <
typename Argument>
92 int fcntl(
int fd,
int cmd,
const Argument& arg)
97 "file descriptor control failed");
109 int ioctl(
int fd,
unsigned long request,
void *arg);
123 int ioctl(
int fd,
unsigned long request,
const void *arg);
135 template <
typename Argument>
136 int ioctl(
int fd,
unsigned long request, Argument& arg)
138 return w::ioctl(
fd, request,
reinterpret_cast<void *
>(&arg));
154 template <
typename Argument>
155 int ioctl(
int fd,
unsigned long request,
const Argument& arg)
157 return w::ioctl(
fd, request,
reinterpret_cast<const void *
>(&arg));
169 template <
typename Argument>
173 w::ioctl(
fd, request,
reinterpret_cast<void *
>(&arg));
188#if (__cplusplus >= 201709L)
201 w::mmap_handle mmap(
void *address,
std::size_t length,
int prot,
int flags,
int fd, off_t offset);
212 w::fd open(
const char *pathname,
int flags);
223 w::fd open(
const char *pathname,
int flags, mode_t mode);
An RAII handle type which owns an opaque resource of a specified type, and calls a designated functio...
Definition: handle.hpp:40
Definition: assert.hpp:13
w::handle< int, -1, ::close > fd
An RAII util::handle type for POSIX file descriptors.
Definition: posix.hpp:25
std::size_t read(int fd, void *buf, std::size_t count)
Reads data from a file descriptor.
Definition: posix.cpp:89
T throw_if_eq(T value, T x, const char *message)
Throw a std::system_error with errno if value == x, otherwise return value.
Definition: assert.hpp:25
std::pair< w::fd, w::fd > pipe()
Creates a pipe.
Definition: posix.cpp:77
w::fd open(const char *pathname, int flags)
Opens and possibly creates a file.
Definition: posix.cpp:61
std::size_t write(int fd, const void *buf, std::size_t count)
Writes data to a file descriptor.
Definition: posix.cpp:107
int ioctl(int fd, unsigned long request, void *arg)
Controls a device.
Definition: posix.cpp:26
int fcntl(int fd, int cmd)
Controls a file descriptor.
Definition: posix.cpp:18
std::size_t readv(int fd, const struct iovec *iov, int iovcnt)
Reads data from a file descriptor.
Definition: posix.cpp:98
std::size_t writev(int fd, const struct iovec *iov, int iovcnt)
Writes data to a file descriptor.
Definition: posix.cpp:116
std::size_t lseek(int fd, off_t offset, int whence)
Sets the position of a file pointer for a file descriptor.
Definition: posix.cpp:42
A structure holding details about a memory-mapped file or device.
Definition: posix.hpp:32
constexpr memory_region() noexcept
Constructs an empty memory region.
Definition: posix.hpp:46
constexpr bool operator!=(const memory_region &rhs) const noexcept
Compares two memory regions.
Definition: posix.hpp:53
std::size_t length
The length of the mapping in bytes.
Definition: posix.hpp:34
constexpr memory_region(void *address, std::size_t length) noexcept
Constructs a memory region.
Definition: posix.hpp:41
void * address
The (actual, not requested) base address of the mapping.
Definition: posix.hpp:33