aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/raw_ostream.cpp
diff options
context:
space:
mode:
authorFrancois Pichet <pichet2000@gmail.com>2010-10-14 20:30:58 +0000
committerFrancois Pichet <pichet2000@gmail.com>2010-10-14 20:30:58 +0000
commita3037c3abd6f7aa2f4187b169b22d96e96a73250 (patch)
tree5085e58cf3e195b0d0129e48050968530dbdfbd1 /llvm/lib/Support/raw_ostream.cpp
parent6843141d39e7f877b695f639b1e0374673a790f0 (diff)
downloadllvm-a3037c3abd6f7aa2f4187b169b22d96e96a73250.zip
llvm-a3037c3abd6f7aa2f4187b169b22d96e96a73250.tar.gz
llvm-a3037c3abd6f7aa2f4187b169b22d96e96a73250.tar.bz2
Always use binary mode for output stream. This is important to prevent unwanted end of line conversion on Windows. Should not affect Unix where O_BINARY is not defined. This fix /clang/test/lexer/preamble.c XFAIL on WIN32.
llvm-svn: 116509
Diffstat (limited to 'llvm/lib/Support/raw_ostream.cpp')
-rw-r--r--llvm/lib/Support/raw_ostream.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 4c947c7..f3bcfa1 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -409,6 +409,19 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
ShouldClose = true;
}
+/// raw_fd_ostream ctor - FD is the file descriptor that this writes to. If
+/// ShouldClose is true, this closes the file when the stream is destroyed.
+raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered)
+ : raw_ostream(unbuffered), FD(fd),
+ ShouldClose(shouldClose), Error(false) {
+#ifdef O_BINARY
+ // Setting STDOUT and STDERR to binary mode is necessary in Win32
+ // to avoid undesirable linefeed conversion.
+ if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
+ setmode(fd, O_BINARY);
+#endif
+}
+
raw_fd_ostream::~raw_fd_ostream() {
if (FD >= 0) {
flush();