summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-07-16 19:44:17 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-07-16 19:44:17 +0000
commitc1b49b56d4132efa2e06deb8f23508d0de4c8800 (patch)
treeac30ab59f60f12465f5b7ffd0823b08a711770e8 /tools
parent1a9c39e52a2b1ce474dec773e77d12ae4c335a71 (diff)
downloadllvm-c1b49b56d4132efa2e06deb8f23508d0de4c8800.tar.gz
llvm-c1b49b56d4132efa2e06deb8f23508d0de4c8800.tar.bz2
llvm-c1b49b56d4132efa2e06deb8f23508d0de4c8800.tar.xz
Add a wrapper for open.
This centralizes the handling of O_BINARY and opens the way for hiding more differences (like how open behaves with directories). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186447 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/bugpoint/OptimizerDriver.cpp2
-rw-r--r--tools/llc/llc.cpp5
-rw-r--r--tools/llvm-ar/llvm-ar.cpp25
-rw-r--r--tools/llvm-as/llvm-as.cpp5
-rw-r--r--tools/llvm-dis/llvm-dis.cpp5
-rw-r--r--tools/llvm-extract/llvm-extract.cpp3
-rw-r--r--tools/llvm-link/llvm-link.cpp3
-rw-r--r--tools/llvm-mc/llvm-mc.cpp4
-rw-r--r--tools/llvm-stress/llvm-stress.cpp2
-rw-r--r--tools/lto/LTOCodeGenerator.cpp3
-rw-r--r--tools/opt/opt.cpp4
11 files changed, 23 insertions, 38 deletions
diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp
index 36d536ab89..0c39b9d6fc 100644
--- a/tools/bugpoint/OptimizerDriver.cpp
+++ b/tools/bugpoint/OptimizerDriver.cpp
@@ -68,7 +68,7 @@ bool BugDriver::writeProgramToFile(const std::string &Filename, int FD,
bool BugDriver::writeProgramToFile(const std::string &Filename,
const Module *M) const {
std::string ErrInfo;
- tool_output_file Out(Filename.c_str(), ErrInfo, raw_fd_ostream::F_Binary);
+ tool_output_file Out(Filename.c_str(), ErrInfo, sys::fs::F_Binary);
if (ErrInfo.empty())
return writeProgramToFileAux(Out, M);
return true;
diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp
index bcabafc467..b5852aad11 100644
--- a/tools/llc/llc.cpp
+++ b/tools/llc/llc.cpp
@@ -145,8 +145,9 @@ static tool_output_file *GetOutputStream(const char *TargetName,
// Open the file.
std::string error;
- unsigned OpenFlags = 0;
- if (Binary) OpenFlags |= raw_fd_ostream::F_Binary;
+ sys::fs::OpenFlags OpenFlags = sys::fs::F_None;
+ if (Binary)
+ OpenFlags |= sys::fs::F_Binary;
tool_output_file *FDOut = new tool_output_file(OutputFilename.c_str(), error,
OpenFlags);
if (!error.empty()) {
diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp
index d65f9ecc9f..9b55a8130b 100644
--- a/tools/llvm-ar/llvm-ar.cpp
+++ b/tools/llvm-ar/llvm-ar.cpp
@@ -26,7 +26,6 @@
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cstdlib>
-#include <fcntl.h>
#include <memory>
#if !defined(_MSC_VER) && !defined(__MINGW32__)
@@ -299,19 +298,14 @@ static void doDisplayTable(StringRef Name, object::Archive::child_iterator I) {
// Implement the 'x' operation. This function extracts files back to the file
// system.
static void doExtract(StringRef Name, object::Archive::child_iterator I) {
- // Open up a file stream for writing
- // FIXME: we should abstract this, O_BINARY in particular.
- int OpenFlags = O_TRUNC | O_WRONLY | O_CREAT;
-#ifdef O_BINARY
- OpenFlags |= O_BINARY;
-#endif
-
// Retain the original mode.
sys::fs::perms Mode = I->getAccessMode();
+ SmallString<128> Storage = Name;
- int FD = open(Name.str().c_str(), OpenFlags, Mode);
- if (FD < 0)
- fail("Could not open output file");
+ int FD;
+ failIfError(
+ sys::fs::openFileForWrite(Storage.c_str(), FD, sys::fs::F_None, Mode),
+ Storage.c_str());
{
raw_fd_ostream file(FD, false);
@@ -559,13 +553,8 @@ static void performWriteOperation(ArchiveOperation Operation,
if (I->isNewMember()) {
const char *FileName = I->getNew();
- int OpenFlags = O_RDONLY;
-#ifdef O_BINARY
- OpenFlags |= O_BINARY;
-#endif
- int FD = ::open(FileName, OpenFlags);
- if (FD == -1)
- return failIfError(error_code(errno, posix_category()), FileName);
+ int FD;
+ failIfError(sys::fs::openFileForRead(FileName, FD), FileName);
sys::fs::file_status Status;
failIfError(sys::fs::status(FD, Status), FileName);
diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp
index d6f191961d..b2e44ef9d3 100644
--- a/tools/llvm-as/llvm-as.cpp
+++ b/tools/llvm-as/llvm-as.cpp
@@ -69,9 +69,8 @@ static void WriteOutputFile(const Module *M) {
}
std::string ErrorInfo;
- OwningPtr<tool_output_file> Out
- (new tool_output_file(OutputFilename.c_str(), ErrorInfo,
- raw_fd_ostream::F_Binary));
+ OwningPtr<tool_output_file> Out(new tool_output_file(
+ OutputFilename.c_str(), ErrorInfo, sys::fs::F_Binary));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
exit(1);
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
index 067955e5cc..87eb34708a 100644
--- a/tools/llvm-dis/llvm-dis.cpp
+++ b/tools/llvm-dis/llvm-dis.cpp
@@ -168,9 +168,8 @@ int main(int argc, char **argv) {
}
std::string ErrorInfo;
- OwningPtr<tool_output_file>
- Out(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
- raw_fd_ostream::F_Binary));
+ OwningPtr<tool_output_file> Out(new tool_output_file(
+ OutputFilename.c_str(), ErrorInfo, sys::fs::F_Binary));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;
diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp
index 2f45b4eae5..9ba68b465d 100644
--- a/tools/llvm-extract/llvm-extract.cpp
+++ b/tools/llvm-extract/llvm-extract.cpp
@@ -265,8 +265,7 @@ int main(int argc, char **argv) {
Passes.add(createStripDeadPrototypesPass()); // Remove dead func decls
std::string ErrorInfo;
- tool_output_file Out(OutputFilename.c_str(), ErrorInfo,
- raw_fd_ostream::F_Binary);
+ tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_Binary);
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;
diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp
index d8d7534e5c..652c414a9d 100644
--- a/tools/llvm-link/llvm-link.cpp
+++ b/tools/llvm-link/llvm-link.cpp
@@ -106,8 +106,7 @@ int main(int argc, char **argv) {
if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;
std::string ErrorInfo;
- tool_output_file Out(OutputFilename.c_str(), ErrorInfo,
- raw_fd_ostream::F_Binary);
+ tool_output_file Out(OutputFilename.c_str(), ErrorInfo, sys::fs::F_Binary);
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;
diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp
index 26c99d5283..f10a614a22 100644
--- a/tools/llvm-mc/llvm-mc.cpp
+++ b/tools/llvm-mc/llvm-mc.cpp
@@ -210,8 +210,8 @@ static tool_output_file *GetOutputStream() {
OutputFilename = "-";
std::string Err;
- tool_output_file *Out = new tool_output_file(OutputFilename.c_str(), Err,
- raw_fd_ostream::F_Binary);
+ tool_output_file *Out =
+ new tool_output_file(OutputFilename.c_str(), Err, sys::fs::F_Binary);
if (!Err.empty()) {
errs() << Err << '\n';
delete Out;
diff --git a/tools/llvm-stress/llvm-stress.cpp b/tools/llvm-stress/llvm-stress.cpp
index fbda1b7b67..15f7abf70e 100644
--- a/tools/llvm-stress/llvm-stress.cpp
+++ b/tools/llvm-stress/llvm-stress.cpp
@@ -702,7 +702,7 @@ int main(int argc, char **argv) {
std::string ErrorInfo;
Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
- raw_fd_ostream::F_Binary));
+ sys::fs::F_Binary));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;
diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp
index 7616aa3d25..c7d14afcf3 100644
--- a/tools/lto/LTOCodeGenerator.cpp
+++ b/tools/lto/LTOCodeGenerator.cpp
@@ -137,8 +137,7 @@ bool LTOCodeGenerator::writeMergedModules(const char *path,
// create output file
std::string ErrInfo;
- tool_output_file Out(path, ErrInfo,
- raw_fd_ostream::F_Binary);
+ tool_output_file Out(path, ErrInfo, sys::fs::F_Binary);
if (!ErrInfo.empty()) {
errMsg = "could not open bitcode file for writing: ";
errMsg += path;
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index 6fc8d6759b..bb8d143e81 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -616,7 +616,7 @@ int main(int argc, char **argv) {
std::string ErrorInfo;
Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
- raw_fd_ostream::F_Binary));
+ sys::fs::F_Binary));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;
@@ -679,7 +679,7 @@ int main(int argc, char **argv) {
std::string ErrorInfo;
Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
- raw_fd_ostream::F_Binary));
+ sys::fs::F_Binary));
if (!ErrorInfo.empty()) {
errs() << ErrorInfo << '\n';
return 1;