diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-08-23 02:51:22 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-08-23 02:51:22 +0000 |
| commit | 9e6f1f160ab6810625629fd1e2dc8a809db83565 (patch) | |
| tree | 1165e8689cce0feb59958dfe42477fa586042971 /llvm/lib/Support/raw_ostream.cpp | |
| parent | 622ddae92b84022892d31e64de88a643e988a707 (diff) | |
| download | bcm5719-llvm-9e6f1f160ab6810625629fd1e2dc8a809db83565.tar.gz bcm5719-llvm-9e6f1f160ab6810625629fd1e2dc8a809db83565.zip | |
Change raw_fd_ostream to take flags as an optional bitmask
instead of as two bools. Use this to add a F_Append flag
which has the obvious behavior.
Other unrelated changes conflated into this patch:
1. REmove EH stuff from llvm-dis and llvm-as, the try blocks
are dead.
2. Simplify the filename inference code in llvm-as/llvm-dis,
because raw_fd_ostream does the right thing with '-'.
3. Switch machine verifier to use raw_ostream instead of ostream
(Which is the thing that needed append in the first place).
llvm-svn: 79807
Diffstat (limited to 'llvm/lib/Support/raw_ostream.cpp')
| -rw-r--r-- | llvm/lib/Support/raw_ostream.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp index 94507bd67ba..2e151118d6a 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -322,8 +322,12 @@ void format_object_base::home() { /// occurs, information about the error is put into ErrorInfo, and the /// stream should be immediately destroyed; the string will be empty /// if no error occurred. -raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary, bool Force, - std::string &ErrorInfo) : pos(0) { +raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo, + unsigned Flags) : pos(0) { + // Verify that we don't have both "append" and "force". + assert((!(Flags & F_Force) || !(Flags & F_Append)) && + "Cannot specify both 'force' and 'append' file creation flags!"); + ErrorInfo.clear(); // Handle "-" as stdout. @@ -331,20 +335,26 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary, bool Force, FD = STDOUT_FILENO; // If user requested binary then put stdout into binary mode if // possible. - if (Binary) + if (Flags & F_Binary) sys::Program::ChangeStdoutToBinary(); ShouldClose = false; return; } - int Flags = O_WRONLY|O_CREAT|O_TRUNC; + int OpenFlags = O_WRONLY|O_CREAT; #ifdef O_BINARY if (Binary) - Flags |= O_BINARY; + OpenFlags |= O_BINARY; #endif - if (!Force) - Flags |= O_EXCL; - FD = open(Filename, Flags, 0664); + + if (Flags & F_Force) + OpenFlags |= O_TRUNC; + else if (Flags & F_Append) + OpenFlags |= O_APPEND; + else + OpenFlags |= O_EXCL; + + FD = open(Filename, OpenFlags, 0664); if (FD < 0) { ErrorInfo = "Error opening output file '" + std::string(Filename) + "'"; ShouldClose = false; @@ -354,14 +364,14 @@ raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary, bool Force, } raw_fd_ostream::~raw_fd_ostream() { - if (FD >= 0) { - flush(); - if (ShouldClose) - if (::close(FD) != 0) - error_detected(); - } + if (FD < 0) return; + flush(); + if (ShouldClose) + if (::close(FD) != 0) + error_detected(); } + void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { assert (FD >= 0 && "File already closed."); pos += Size; |

