Add Thumb2 lsr hooks.
[oota-llvm.git] / lib / Support / raw_ostream.cpp
index 5eaf7bf6a04e395ef24ca37b4160f7cc62dd83cf..dcd33673acd91bbcd6604e38c377ca16518e202d 100644 (file)
@@ -222,6 +222,8 @@ raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) {
 }
 
 void raw_ostream::copy_to_buffer(const char *Ptr, size_t Size) {
+  assert(Size <= size_t(OutBufEnd - OutBufCur) && "Buffer overrun!");
+
   // Handle short strings specially, memcpy isn't very good at very short
   // strings.
   switch (Size) {
@@ -313,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;
   }
   
@@ -409,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) {}