mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 11:17:35 +02:00
Add FileDescriptor::write.
This commit is contained in:
@ -80,6 +80,14 @@ std::streamsize FileDescriptor::read(void *buffer, std::size_t count) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::streamsize FileDescriptor::write(const void *buffer, std::size_t count) {
|
||||||
|
std::streamsize result = 0;
|
||||||
|
FMT_RETRY(result, ::write(fd_, buffer, count));
|
||||||
|
if (result == -1)
|
||||||
|
fmt::ThrowSystemError(errno, "cannot write to file");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
FileDescriptor FileDescriptor::dup(int fd) {
|
FileDescriptor FileDescriptor::dup(int fd) {
|
||||||
int new_fd = 0;
|
int new_fd = 0;
|
||||||
FMT_RETRY(new_fd, ::FMT_POSIX(dup(fd)));
|
FMT_RETRY(new_fd, ::FMT_POSIX(dup(fd)));
|
||||||
|
@ -194,10 +194,14 @@ class FileDescriptor {
|
|||||||
// Returns the file descriptor.
|
// Returns the file descriptor.
|
||||||
int get() const FMT_NOEXCEPT(true) { return fd_; }
|
int get() const FMT_NOEXCEPT(true) { return fd_; }
|
||||||
|
|
||||||
// Attempts to read count chars from the file associated with this file
|
// Attempts to read count bytes from the file associated with this file
|
||||||
// descriptor into the specified buffer.
|
// descriptor into the specified buffer.
|
||||||
std::streamsize read(void *buffer, std::size_t count);
|
std::streamsize read(void *buffer, std::size_t count);
|
||||||
|
|
||||||
|
// Attempts to write count bytes from the specified buffer to the file
|
||||||
|
// associated with this file descriptor.
|
||||||
|
std::streamsize write(const void *buffer, std::size_t count);
|
||||||
|
|
||||||
// Duplicates a file descriptor with the dup function and returns
|
// Duplicates a file descriptor with the dup function and returns
|
||||||
// the duplicate. Throws fmt::SystemError on error.
|
// the duplicate. Throws fmt::SystemError on error.
|
||||||
static FileDescriptor dup(int fd);
|
static FileDescriptor dup(int fd);
|
||||||
|
Reference in New Issue
Block a user