aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support/raw_ostream.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-08-13 23:18:56 +0000
committerDan Gohman <gohman@apple.com>2009-08-13 23:18:56 +0000
commitec9b26100e06d566ccb4516c6fe3f2a685ecd941 (patch)
treef220949d1d8bcc7b469a48bad12c39cec6efa646 /lib/Support/raw_ostream.cpp
parent6c304f2314e5fb00488ac6bdfdac180c0ffd3d09 (diff)
downloadexternal_llvm-ec9b26100e06d566ccb4516c6fe3f2a685ecd941.zip
external_llvm-ec9b26100e06d566ccb4516c6fe3f2a685ecd941.tar.gz
external_llvm-ec9b26100e06d566ccb4516c6fe3f2a685ecd941.tar.bz2
When standard output is a terminal, set outs() to be unbuffered, to
mimic the behavior of stdtout, which is line-buffered when the output is a terminal. This fixes some issues with bugpoint output appearing being printed out of order. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78953 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/raw_ostream.cpp')
-rw-r--r--lib/Support/raw_ostream.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index f0090d8..dcd3367 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -315,6 +315,10 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary, bool Force,
if (Binary)
sys::Program::ChangeStdoutToBinary();
ShouldClose = false;
+ // Mimic stdout by defaulting to unbuffered if the output device
+ // is a terminal.
+ if (sys::Process::StandardOutIsDisplayed())
+ SetUnbuffered();
return;
}
@@ -411,7 +415,13 @@ raw_ostream &raw_fd_ostream::resetColor() {
// raw_stdout/err_ostream
//===----------------------------------------------------------------------===//
-raw_stdout_ostream::raw_stdout_ostream():raw_fd_ostream(STDOUT_FILENO, false) {}
+// Set buffer settings to model stdout and stderr behavior.
+// raw_ostream doesn't support line buffering, so set standard output to be
+// unbuffered when the output device is a terminal. Set standard error to
+// be unbuffered.
+raw_stdout_ostream::raw_stdout_ostream()
+ : raw_fd_ostream(STDOUT_FILENO, false,
+ sys::Process::StandardOutIsDisplayed()) {}
raw_stderr_ostream::raw_stderr_ostream():raw_fd_ostream(STDERR_FILENO, false,
true) {}