diff options
author | Dan Gohman <gohman@apple.com> | 2010-08-18 22:26:19 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-08-18 22:26:19 +0000 |
commit | c825ceefb4add935a418d4fc06efe6f3c420b9d4 (patch) | |
tree | 7a17f8a126361b43815ed08c8593b2cdb9c3f475 /llvm/lib | |
parent | 82656fb0e1ace8d639da3ab1e1082f3526abd618 (diff) | |
download | bcm5719-llvm-c825ceefb4add935a418d4fc06efe6f3c420b9d4.tar.gz bcm5719-llvm-c825ceefb4add935a418d4fc06efe6f3c420b9d4.zip |
Make raw_fd_ostream consider itself the owner of STDOUT_FILENO when
constructed with an output filename of "-". In particular, allow the
file descriptor to be closed, and close the file descriptor in the
destructor if it hasn't been explicitly closed already, to ensure
that any write errors are detected.
llvm-svn: 111436
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Support/raw_ostream.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp index ac118a91a3f..71a2ac5e092 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -377,14 +377,17 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo, ErrorInfo.clear(); - // Handle "-" as stdout. + // Handle "-" as stdout. Note that when we do this, we consider ourself + // the owner of stdout. This means that we can do things like close the + // file descriptor when we're done and set the "binary" flag globally. if (Filename[0] == '-' && Filename[1] == 0) { FD = STDOUT_FILENO; // If user requested binary then put stdout into binary mode if // possible. if (Flags & F_Binary) sys::Program::ChangeStdoutToBinary(); - ShouldClose = false; + // Close stdout when we're done, to detect any output errors. + ShouldClose = true; return; } |