mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-03 20:54:08 +00:00
Fix FileDescriptor::pipe.
This commit is contained in:
parent
8214a5ef5e
commit
e648d289bb
@ -95,17 +95,25 @@ void FileDescriptor::dup2(int fd, ErrorCode &ec) FMT_NOEXCEPT(true) {
|
||||
ec = ErrorCode(errno);
|
||||
}
|
||||
|
||||
void FileDescriptor::pipe(FileDescriptor &read, FileDescriptor &write) {
|
||||
void FileDescriptor::pipe(FileDescriptor &read_fd, FileDescriptor &write_fd) {
|
||||
// Close the descriptors first to make sure that assignments don't throw
|
||||
// and there are no leaks.
|
||||
read.close();
|
||||
write.close();
|
||||
read_fd.close();
|
||||
write_fd.close();
|
||||
int fds[2] = {};
|
||||
if (::pipe(fds) != 0)
|
||||
#ifdef _WIN32
|
||||
// Make the default pipe capacity same as on Linux 2.6.11+.
|
||||
enum { DEFAULT_CAPACITY = 65536 };
|
||||
int result = _pipe(fds, DEFAULT_CAPACITY, _O_BINARY);
|
||||
#else
|
||||
int result = ::pipe(fds);
|
||||
#endif
|
||||
if (result != 0)
|
||||
fmt::ThrowSystemError(errno, "cannot create pipe");
|
||||
// The following assignments don't throw because read and write are closed.
|
||||
read = FileDescriptor(fds[0]);
|
||||
write = FileDescriptor(fds[1]);
|
||||
// The following assignments don't throw because read_fd and write_fd
|
||||
// are closed.
|
||||
read_fd = FileDescriptor(fds[0]);
|
||||
write_fd = FileDescriptor(fds[1]);
|
||||
}
|
||||
|
||||
OutputRedirector::OutputRedirector(FILE *file) : file_(file) {
|
||||
|
@ -204,7 +204,7 @@ class FileDescriptor {
|
||||
|
||||
// Creates a pipe setting up read and write file descriptors for reading
|
||||
// and writing respecively. Throws fmt::SystemError on error.
|
||||
static void pipe(FileDescriptor &read, FileDescriptor &write);
|
||||
static void pipe(FileDescriptor &read_fd, FileDescriptor &write_fd);
|
||||
};
|
||||
|
||||
#if !FMT_USE_RVALUE_REFERENCES
|
||||
|
Loading…
x
Reference in New Issue
Block a user