#endif
#endif
+#ifdef LLVM_ON_WIN32
+#include "Windows/WindowsSupport.h"
+#endif
+
using namespace llvm;
raw_ostream::~raw_ostream() {
return this->operator<<(format("%e", N));
}
-raw_ostream &raw_ostream::operator<<(Printable P) {
- P(*this);
- return *this;
-}
void raw_ostream::flush_nonempty() {
/// closes the file when the stream is destroyed.
raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered)
: raw_pwrite_stream(unbuffered), FD(fd), ShouldClose(shouldClose),
- Error(false), UseAtomicWrites(false) {
+ Error(false) {
if (FD < 0 ) {
ShouldClose = false;
return;
assert(FD >= 0 && "File already closed.");
pos += Size;
- do {
- ssize_t ret;
-
- // Check whether we should attempt to use atomic writes.
- if (LLVM_LIKELY(!UseAtomicWrites)) {
- ret = ::write(FD, Ptr, Size);
- } else {
- // Use ::writev() where available.
-#if defined(HAVE_WRITEV)
- const void *Addr = static_cast<const void *>(Ptr);
- struct iovec IOV = {const_cast<void *>(Addr), Size };
- ret = ::writev(FD, &IOV, 1);
+#ifndef LLVM_ON_WIN32
+ bool ShouldWriteInChunks = false;
#else
- ret = ::write(FD, Ptr, Size);
+ // Writing a large size of output to Windows console returns ENOMEM. It seems
+ // that, prior to Windows 8, WriteFile() is redirecting to WriteConsole(), and
+ // the latter has a size limit (66000 bytes or less, depending on heap usage).
+ bool ShouldWriteInChunks = !!::_isatty(FD) && !RunningWindows8OrGreater();
#endif
- }
+
+ do {
+ size_t ChunkSize = Size;
+ if (ChunkSize > 32767 && ShouldWriteInChunks)
+ ChunkSize = 32767;
+
+ ssize_t ret = ::write(FD, Ptr, ChunkSize);
if (ret < 0) {
// If it's a recoverable error, swallow it and retry the write.