llvm.org GIT mirror llvm / e77e434
PR3478: raw_ostream should not buffer stderr - Add unbuffered flag to raw_ostream, forwarded by raw_fd_ostream and used by raw_stderr_ostream. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66545 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 10 years ago
2 changed file(s) with 24 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
3131 class raw_ostream {
3232 protected:
3333 char *OutBufStart, *OutBufEnd, *OutBufCur;
34 public:
35 raw_ostream() {
34 bool Unbuffered;
35
36 public:
37 raw_ostream(bool unbuffered=false) : Unbuffered(unbuffered) {
3638 // Start out ready to flush.
3739 OutBufStart = OutBufEnd = OutBufCur = 0;
3840 }
5658 OutBufStart = new char[Size];
5759 OutBufEnd = OutBufStart+Size;
5860 OutBufCur = OutBufStart;
61 }
62
63 /// SetUnbuffered - Set the streams buffering status. When
64 /// unbuffered the stream will flush after every write. This routine
65 /// will also flush the buffer immediately when the stream is being
66 /// set to unbuffered.
67 void SetUnbuffered(bool unbuffered) {
68 Unbuffered = unbuffered;
69 if (Unbuffered)
70 flush();
5971 }
6072
6173 //===--------------------------------------------------------------------===//
164176 raw_fd_ostream(const char *Filename, bool Binary, std::string &ErrorInfo);
165177
166178 /// raw_fd_ostream ctor - FD is the file descriptor that this writes to. If
167 /// ShouldClose is true, this closes the file when
168 raw_fd_ostream(int fd, bool shouldClose) : FD(fd), ShouldClose(shouldClose) {}
169
179 /// ShouldClose is true, this closes the file when the stream is destroyed.
180 raw_fd_ostream(int fd, bool shouldClose,
181 bool unbuffered=false) : raw_ostream(unbuffered), FD(fd),
182 ShouldClose(shouldClose) {}
183
170184 ~raw_fd_ostream();
171185
172186 /// flush_impl - The is the piece of the class that is implemented by
140140 break;
141141 }
142142 OutBufCur += Size;
143
144 if (Unbuffered)
145 flush_impl();
143146 return *this;
144147 }
145148
265268 //===----------------------------------------------------------------------===//
266269
267270 raw_stdout_ostream::raw_stdout_ostream():raw_fd_ostream(STDOUT_FILENO, false) {}
268 raw_stderr_ostream::raw_stderr_ostream():raw_fd_ostream(STDERR_FILENO, false) {}
271 raw_stderr_ostream::raw_stderr_ostream():raw_fd_ostream(STDERR_FILENO, false,
272 true) {}
269273
270274 // An out of line virtual method to provide a home for the class vtable.
271275 void raw_stdout_ostream::handle() {}