summaryrefslogtreecommitdiff
path: root/lib/Support
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-08-17 23:11:56 +0000
committerChris Lattner <sabre@nondot.org>2010-08-17 23:11:56 +0000
commit93d81b697c054c04d1995af0393f20ce23f520d4 (patch)
treea39deaca7b769e4681ba1648438ab184eb4be3ce /lib/Support
parent73ebaff79f2a26d76cccd37d176f05f32b09ad2e (diff)
downloadllvm-93d81b697c054c04d1995af0393f20ce23f520d4.tar.gz
llvm-93d81b697c054c04d1995af0393f20ce23f520d4.tar.bz2
llvm-93d81b697c054c04d1995af0393f20ce23f520d4.tar.xz
Fix the rest of rdar://8318441 which happens when a raw_fd_ostream
(e.g. errs()) fails in close() due to (e.g.) a broken pipe. As previously written, the had_error() flag would get set and then the raw_ostream dtor would report a fatal error. There is nothing the client can do about this and we have no way to report the error, so just eat it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111321 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/raw_ostream.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index ac118a91a3..76c83d16ac 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -415,15 +415,31 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
raw_fd_ostream::~raw_fd_ostream() {
if (FD < 0) return;
- flush();
- if (ShouldClose)
- while (::close(FD) != 0)
- if (errno != EINTR) {
- error_detected();
- break;
- }
+ if (!ShouldClose) {
+ flush();
+ return;
+ }
+
+ bool HadError = has_error();
+ close();
+
+ // If we had a failure closing the stream, there is no way for the client to
+ // handle it, just eat the failure.
+ if (!HadError && has_error())
+ clear_error();
}
+void raw_fd_ostream::close() {
+ assert(ShouldClose);
+ ShouldClose = false;
+ flush();
+ while (::close(FD) != 0)
+ if (errno != EINTR) {
+ error_detected();
+ break;
+ }
+ FD = -1;
+}
void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
assert(FD >= 0 && "File already closed.");
@@ -461,18 +477,6 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
} while (Size > 0);
}
-void raw_fd_ostream::close() {
- assert(ShouldClose);
- ShouldClose = false;
- flush();
- while (::close(FD) != 0)
- if (errno != EINTR) {
- error_detected();
- break;
- }
- FD = -1;
-}
-
uint64_t raw_fd_ostream::seek(uint64_t off) {
flush();
pos = ::lseek(FD, off, SEEK_SET);