From e648d289bb4050c9f8ea1cc71cd7450174b9d82a Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 3 May 2014 10:25:46 -0700 Subject: [PATCH] Fix FileDescriptor::pipe. --- test/gtest-extra.cc | 22 +++++++++++++++------- test/gtest-extra.h | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/test/gtest-extra.cc b/test/gtest-extra.cc index f9550b5c..74628083 100644 --- a/test/gtest-extra.cc +++ b/test/gtest-extra.cc @@ -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) { diff --git a/test/gtest-extra.h b/test/gtest-extra.h index 6e749006..bd0eaaa7 100644 --- a/test/gtest-extra.h +++ b/test/gtest-extra.h @@ -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