Always use binary mode for output stream. This is important to prevent unwanted end...
authorFrancois Pichet <pichet2000@gmail.com>
Thu, 14 Oct 2010 20:30:58 +0000 (20:30 +0000)
committerFrancois Pichet <pichet2000@gmail.com>
Thu, 14 Oct 2010 20:30:58 +0000 (20:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116509 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/raw_ostream.h
lib/Support/raw_ostream.cpp

index 6c20845aa741302f304388fb5b893a8ab69bfc84..6bc8935b1464c18d90c6b6e47e96f5cf5bdc5a86 100644 (file)
@@ -349,10 +349,7 @@ public:
 
   /// 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(int fd, bool shouldClose,
-                 bool unbuffered=false) : raw_ostream(unbuffered), FD(fd),
-                                          ShouldClose(shouldClose),
-                                          Error(false) {}
+  raw_fd_ostream(int fd, bool shouldClose, bool unbuffered=false);
 
   ~raw_fd_ostream();
 
index 4c947c705532c08582bab49bd298023e4125f59a..f3bcfa1b14a51f9e7995d15e6ecf2a91eb5e7eda 100644 (file)
@@ -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();