[llvm] r186447 - Add a wrapper for open.
Rafael Espindola
rafael.espindola at gmail.com
Tue Jul 16 12:44:17 PDT 2013
Author: rafael
Date: Tue Jul 16 14:44:17 2013
New Revision: 186447
URL: http://llvm.org/viewvc/llvm-project?rev=186447&view=rev
Log:
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).
Modified:
llvm/trunk/include/llvm/Support/FileSystem.h
llvm/trunk/include/llvm/Support/ToolOutputFile.h
llvm/trunk/include/llvm/Support/raw_ostream.h
llvm/trunk/lib/Bitcode/Writer/BitWriter.cpp
llvm/trunk/lib/CodeGen/MachineVerifier.cpp
llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp
llvm/trunk/lib/Support/DataStream.cpp
llvm/trunk/lib/Support/MemoryBuffer.cpp
llvm/trunk/lib/Support/Path.cpp
llvm/trunk/lib/Support/Timer.cpp
llvm/trunk/lib/Support/ToolOutputFile.cpp
llvm/trunk/lib/Support/raw_ostream.cpp
llvm/trunk/lib/Target/TargetMachineC.cpp
llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
llvm/trunk/tools/llc/llc.cpp
llvm/trunk/tools/llvm-ar/llvm-ar.cpp
llvm/trunk/tools/llvm-as/llvm-as.cpp
llvm/trunk/tools/llvm-dis/llvm-dis.cpp
llvm/trunk/tools/llvm-extract/llvm-extract.cpp
llvm/trunk/tools/llvm-link/llvm-link.cpp
llvm/trunk/tools/llvm-mc/llvm-mc.cpp
llvm/trunk/tools/llvm-stress/llvm-stress.cpp
llvm/trunk/tools/lto/LTOCodeGenerator.cpp
llvm/trunk/tools/opt/opt.cpp
llvm/trunk/unittests/Support/Path.cpp
llvm/trunk/utils/FileUpdate/FileUpdate.cpp
Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Tue Jul 16 14:44:17 2013
@@ -611,6 +611,37 @@ error_code createTemporaryFile(const Twi
error_code createUniqueDirectory(const Twine &Prefix,
SmallVectorImpl<char> &ResultPath);
+enum OpenFlags {
+ F_None = 0,
+
+ /// F_Excl - When opening a file, this flag makes raw_fd_ostream
+ /// report an error if the file already exists.
+ F_Excl = 1,
+
+ /// F_Append - When opening a file, if it already exists append to the
+ /// existing file instead of returning an error. This may not be specified
+ /// with F_Excl.
+ F_Append = 2,
+
+ /// F_Binary - The file should be opened in binary mode on platforms that
+ /// make this distinction.
+ F_Binary = 4
+};
+
+inline OpenFlags operator|(OpenFlags A, OpenFlags B) {
+ return OpenFlags(unsigned(A) | unsigned(B));
+}
+
+inline OpenFlags &operator|=(OpenFlags &A, OpenFlags B) {
+ A = A | B;
+ return A;
+}
+
+error_code openFileForWrite(const Twine &Name, int &ResultFD, OpenFlags Flags,
+ unsigned Mode = 0666);
+
+error_code openFileForRead(const Twine &Name, int &ResultFD);
+
/// @brief Canonicalize path.
///
/// Sets result to the file system's idea of what path is. The result is always
Modified: llvm/trunk/include/llvm/Support/ToolOutputFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ToolOutputFile.h?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ToolOutputFile.h (original)
+++ llvm/trunk/include/llvm/Support/ToolOutputFile.h Tue Jul 16 14:44:17 2013
@@ -47,7 +47,7 @@ public:
/// tool_output_file - This constructor's arguments are passed to
/// to raw_fd_ostream's constructor.
tool_output_file(const char *filename, std::string &ErrorInfo,
- unsigned Flags = 0);
+ sys::fs::OpenFlags Flags = sys::fs::F_None);
tool_output_file(const char *Filename, int FD);
Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
+++ llvm/trunk/include/llvm/Support/raw_ostream.h Tue Jul 16 14:44:17 2013
@@ -17,6 +17,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/FileSystem.h"
namespace llvm {
class format_object_base;
@@ -335,22 +336,6 @@ class raw_fd_ostream : public raw_ostrea
void error_detected() { Error = true; }
public:
-
- enum {
- /// F_Excl - When opening a file, this flag makes raw_fd_ostream
- /// report an error if the file already exists.
- F_Excl = 1,
-
- /// F_Append - When opening a file, if it already exists append to the
- /// existing file instead of returning an error. This may not be specified
- /// with F_Excl.
- F_Append = 2,
-
- /// F_Binary - The file should be opened in binary mode on platforms that
- /// make this distinction.
- F_Binary = 4
- };
-
/// raw_fd_ostream - Open the specified file for writing. If an error 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.
@@ -362,7 +347,7 @@ public:
/// file descriptor when it is done (this is necessary to detect
/// output errors).
raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
- unsigned Flags = 0);
+ sys::fs::OpenFlags Flags = sys::fs::F_None);
/// 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.
Modified: llvm/trunk/lib/Bitcode/Writer/BitWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitWriter.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitWriter.cpp Tue Jul 16 14:44:17 2013
@@ -18,7 +18,7 @@ using namespace llvm;
int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path) {
std::string ErrorInfo;
- raw_fd_ostream OS(Path, ErrorInfo, raw_fd_ostream::F_Binary);
+ raw_fd_ostream OS(Path, ErrorInfo, sys::fs::F_Binary);
if (!ErrorInfo.empty())
return -1;
Modified: llvm/trunk/lib/CodeGen/MachineVerifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineVerifier.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineVerifier.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineVerifier.cpp Tue Jul 16 14:44:17 2013
@@ -271,8 +271,7 @@ bool MachineVerifier::runOnMachineFuncti
raw_ostream *OutFile = 0;
if (OutFileName) {
std::string ErrorInfo;
- OutFile = new raw_fd_ostream(OutFileName, ErrorInfo,
- raw_fd_ostream::F_Append);
+ OutFile = new raw_fd_ostream(OutFileName, ErrorInfo, sys::fs::F_Append);
if (!ErrorInfo.empty()) {
errs() << "Error opening '" << OutFileName << "': " << ErrorInfo << '\n';
exit(1);
Modified: llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/DarwinAsmParser.cpp Tue Jul 16 14:44:17 2013
@@ -593,7 +593,7 @@ bool DarwinAsmParser::ParseDirectiveSecu
raw_ostream *OS = getContext().getSecureLog();
if (OS == NULL) {
std::string Err;
- OS = new raw_fd_ostream(SecureLogFile, Err, raw_fd_ostream::F_Append);
+ OS = new raw_fd_ostream(SecureLogFile, Err, sys::fs::F_Append);
if (!Err.empty()) {
delete OS;
return Error(IDLoc, Twine("can't open secure log file: ") +
Modified: llvm/trunk/lib/Support/DataStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/DataStream.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/lib/Support/DataStream.cpp (original)
+++ llvm/trunk/lib/Support/DataStream.cpp Tue Jul 16 14:44:17 2013
@@ -17,6 +17,7 @@
#define DEBUG_TYPE "Data-stream"
#include "llvm/Support/DataStream.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/system_error.h"
#include <cerrno>
@@ -27,7 +28,6 @@
#else
#include <io.h>
#endif
-#include <fcntl.h>
using namespace llvm;
// Interface goals:
@@ -69,15 +69,8 @@ public:
sys::ChangeStdinToBinary();
return error_code::success();
}
-
- int OpenFlags = O_RDONLY;
-#ifdef O_BINARY
- OpenFlags |= O_BINARY; // Open input file in binary mode on win32.
-#endif
- Fd = ::open(Filename.c_str(), OpenFlags);
- if (Fd == -1)
- return error_code(errno, posix_category());
- return error_code::success();
+
+ return sys::fs::openFileForRead(Filename, Fd);
}
};
Modified: llvm/trunk/lib/Support/MemoryBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MemoryBuffer.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)
+++ llvm/trunk/lib/Support/MemoryBuffer.cpp Tue Jul 16 14:44:17 2013
@@ -41,7 +41,6 @@
#define S_ISBLK(x) (0)
#endif
#endif
-#include <fcntl.h>
using namespace llvm;
//===----------------------------------------------------------------------===//
@@ -253,13 +252,10 @@ error_code MemoryBuffer::getFile(const c
OwningPtr<MemoryBuffer> &result,
int64_t FileSize,
bool RequiresNullTerminator) {
- int OpenFlags = O_RDONLY;
-#ifdef O_BINARY
- OpenFlags |= O_BINARY; // Open input file in binary mode on win32.
-#endif
- int FD = ::open(Filename, OpenFlags);
- if (FD == -1)
- return error_code(errno, posix_category());
+ int FD;
+ error_code EC = sys::fs::openFileForRead(Filename, FD);
+ if (EC)
+ return EC;
error_code ret = getOpenFile(FD, Filename, result, FileSize, FileSize,
0, RequiresNullTerminator);
Modified: llvm/trunk/lib/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Path.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Path.cpp (original)
+++ llvm/trunk/lib/Support/Path.cpp Tue Jul 16 14:44:17 2013
@@ -18,6 +18,7 @@
#include <cctype>
#include <cstdio>
#include <cstring>
+#include <fcntl.h>
#if !defined(_MSC_VER) && !defined(__MINGW32__)
#include <unistd.h>
@@ -691,6 +692,51 @@ error_code createUniqueDirectory(const T
true, 0, FS_Dir);
}
+error_code openFileForWrite(const Twine &Name, int &ResultFD,
+ sys::fs::OpenFlags Flags, unsigned Mode) {
+ // Verify that we don't have both "append" and "excl".
+ assert((!(Flags & sys::fs::F_Excl) || !(Flags & sys::fs::F_Append)) &&
+ "Cannot specify both 'excl' and 'append' file creation flags!");
+
+ int OpenFlags = O_WRONLY | O_CREAT;
+
+#ifdef O_BINARY
+ if (Flags & F_Binary)
+ OpenFlags |= O_BINARY;
+#endif
+
+ if (Flags & F_Append)
+ OpenFlags |= O_APPEND;
+ else
+ OpenFlags |= O_TRUNC;
+
+ if (Flags & F_Excl)
+ OpenFlags |= O_EXCL;
+
+ SmallString<128> Storage;
+ StringRef P = Name.toNullTerminatedStringRef(Storage);
+ while ((ResultFD = open(P.begin(), OpenFlags, Mode)) < 0) {
+ if (errno != EINTR)
+ return error_code(errno, system_category());
+ }
+ return error_code::success();
+}
+
+error_code openFileForRead(const Twine &Name, int &ResultFD) {
+ int OpenFlags = O_RDONLY;
+#ifdef O_BINARY
+ OpenFlags |= O_BINARY; // Open input file in binary mode on win32.
+#endif
+
+ SmallString<128> Storage;
+ StringRef P = Name.toNullTerminatedStringRef(Storage);
+ while ((ResultFD = open(P.begin(), OpenFlags)) < 0) {
+ if (errno != EINTR)
+ return error_code(errno, system_category());
+ }
+ return error_code::success();
+}
+
error_code make_absolute(SmallVectorImpl<char> &path) {
StringRef p(path.data(), path.size());
Modified: llvm/trunk/lib/Support/Timer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Timer.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Timer.cpp (original)
+++ llvm/trunk/lib/Support/Timer.cpp Tue Jul 16 14:44:17 2013
@@ -66,8 +66,8 @@ raw_ostream *llvm::CreateInfoOutputFile(
// compensate for this, the test-suite Makefiles have code to delete the
// info output file before running commands which write to it.
std::string Error;
- raw_ostream *Result = new raw_fd_ostream(OutputFilename.c_str(),
- Error, raw_fd_ostream::F_Append);
+ raw_ostream *Result =
+ new raw_fd_ostream(OutputFilename.c_str(), Error, sys::fs::F_Append);
if (Error.empty())
return Result;
Modified: llvm/trunk/lib/Support/ToolOutputFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ToolOutputFile.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ToolOutputFile.cpp (original)
+++ llvm/trunk/lib/Support/ToolOutputFile.cpp Tue Jul 16 14:44:17 2013
@@ -37,9 +37,8 @@ tool_output_file::CleanupInstaller::~Cle
}
tool_output_file::tool_output_file(const char *filename, std::string &ErrorInfo,
- unsigned Flags)
- : Installer(filename),
- OS(filename, ErrorInfo, Flags) {
+ sys::fs::OpenFlags Flags)
+ : Installer(filename), OS(filename, ErrorInfo, Flags) {
// If open fails, no cleanup is needed.
if (!ErrorInfo.empty())
Installer.Keep = true;
Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Tue Jul 16 14:44:17 2013
@@ -18,6 +18,7 @@
#include "llvm/Config/config.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Program.h"
@@ -25,14 +26,10 @@
#include <cctype>
#include <cerrno>
#include <sys/stat.h>
-#include <sys/types.h>
#if defined(HAVE_UNISTD_H)
# include <unistd.h>
#endif
-#if defined(HAVE_FCNTL_H)
-# include <fcntl.h>
-#endif
#if defined(HAVE_SYS_UIO_H) && defined(HAVE_WRITEV)
# include <sys/uio.h>
#endif
@@ -43,7 +40,6 @@
#if defined(_MSC_VER)
#include <io.h>
-#include <fcntl.h>
#ifndef STDIN_FILENO
# define STDIN_FILENO 0
#endif
@@ -424,14 +420,9 @@ void format_object_base::home() {
/// stream should be immediately destroyed; the string will be empty
/// if no error occurred.
raw_fd_ostream::raw_fd_ostream(const char *Filename, std::string &ErrorInfo,
- unsigned Flags)
- : Error(false), UseAtomicWrites(false), pos(0)
-{
+ sys::fs::OpenFlags Flags)
+ : Error(false), UseAtomicWrites(false), pos(0) {
assert(Filename != 0 && "Filename is null");
- // Verify that we don't have both "append" and "excl".
- assert((!(Flags & F_Excl) || !(Flags & F_Append)) &&
- "Cannot specify both 'excl' and 'append' file creation flags!");
-
ErrorInfo.clear();
// Handle "-" as stdout. Note that when we do this, we consider ourself
@@ -441,32 +432,19 @@ raw_fd_ostream::raw_fd_ostream(const cha
FD = STDOUT_FILENO;
// If user requested binary then put stdout into binary mode if
// possible.
- if (Flags & F_Binary)
+ if (Flags & sys::fs::F_Binary)
sys::ChangeStdoutToBinary();
// Close stdout when we're done, to detect any output errors.
ShouldClose = true;
return;
}
- int OpenFlags = O_WRONLY|O_CREAT;
-#ifdef O_BINARY
- if (Flags & F_Binary)
- OpenFlags |= O_BINARY;
-#endif
+ error_code EC = sys::fs::openFileForWrite(Filename, FD, Flags);
- if (Flags & F_Append)
- OpenFlags |= O_APPEND;
- else
- OpenFlags |= O_TRUNC;
- if (Flags & F_Excl)
- OpenFlags |= O_EXCL;
-
- while ((FD = open(Filename, OpenFlags, 0666)) < 0) {
- if (errno != EINTR) {
- ErrorInfo = "Error opening output file '" + std::string(Filename) + "'";
- ShouldClose = false;
- return;
- }
+ if (EC) {
+ ErrorInfo = "Error opening output file '" + std::string(Filename) + "'";
+ ShouldClose = false;
+ return;
}
// Ok, we successfully opened the file, so it'll need to be closed.
Modified: llvm/trunk/lib/Target/TargetMachineC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachineC.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachineC.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachineC.cpp Tue Jul 16 14:44:17 2013
@@ -200,7 +200,7 @@ static LLVMBool LLVMTargetMachineEmit(LL
LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
char* Filename, LLVMCodeGenFileType codegen, char** ErrorMessage) {
std::string error;
- raw_fd_ostream dest(Filename, error, raw_fd_ostream::F_Binary);
+ raw_fd_ostream dest(Filename, error, sys::fs::F_Binary);
formatted_raw_ostream destf(dest);
if (!error.empty()) {
*ErrorMessage = strdup(error.c_str());
Modified: llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp Tue Jul 16 14:44:17 2013
@@ -426,7 +426,7 @@ void GCOVProfiler::emitProfileNotes() {
DICompileUnit CU(CU_Nodes->getOperand(i));
std::string ErrorInfo;
raw_fd_ostream out(mangleName(CU, "gcno").c_str(), ErrorInfo,
- raw_fd_ostream::F_Binary);
+ sys::fs::F_Binary);
out.write("oncg", 4);
out.write(ReversedVersion, 4);
out.write("MVLL", 4);
Modified: llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/OptimizerDriver.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/OptimizerDriver.cpp (original)
+++ llvm/trunk/tools/bugpoint/OptimizerDriver.cpp Tue Jul 16 14:44:17 2013
@@ -68,7 +68,7 @@ bool BugDriver::writeProgramToFile(const
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;
Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Tue Jul 16 14:44:17 2013
@@ -145,8 +145,9 @@ static tool_output_file *GetOutputStream
// 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()) {
Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Tue Jul 16 14:44:17 2013
@@ -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 Nam
// 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(Archiv
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);
Modified: llvm/trunk/tools/llvm-as/llvm-as.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-as/llvm-as.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-as/llvm-as.cpp (original)
+++ llvm/trunk/tools/llvm-as/llvm-as.cpp Tue Jul 16 14:44:17 2013
@@ -69,9 +69,8 @@ static void WriteOutputFile(const Module
}
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);
Modified: llvm/trunk/tools/llvm-dis/llvm-dis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dis/llvm-dis.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dis/llvm-dis.cpp (original)
+++ llvm/trunk/tools/llvm-dis/llvm-dis.cpp Tue Jul 16 14:44:17 2013
@@ -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;
Modified: llvm/trunk/tools/llvm-extract/llvm-extract.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-extract/llvm-extract.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-extract/llvm-extract.cpp (original)
+++ llvm/trunk/tools/llvm-extract/llvm-extract.cpp Tue Jul 16 14:44:17 2013
@@ -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;
Modified: llvm/trunk/tools/llvm-link/llvm-link.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-link/llvm-link.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-link/llvm-link.cpp (original)
+++ llvm/trunk/tools/llvm-link/llvm-link.cpp Tue Jul 16 14:44:17 2013
@@ -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;
Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Tue Jul 16 14:44:17 2013
@@ -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;
Modified: llvm/trunk/tools/llvm-stress/llvm-stress.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-stress/llvm-stress.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-stress/llvm-stress.cpp (original)
+++ llvm/trunk/tools/llvm-stress/llvm-stress.cpp Tue Jul 16 14:44:17 2013
@@ -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;
Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Tue Jul 16 14:44:17 2013
@@ -137,8 +137,7 @@ bool LTOCodeGenerator::writeMergedModule
// 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;
Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Tue Jul 16 14:44:17 2013
@@ -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;
Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Tue Jul 16 14:44:17 2013
@@ -350,8 +350,7 @@ TEST_F(FileSystemTest, Magic) {
SmallString<128> file_pathname(TestDirectory);
path::append(file_pathname, i->filename);
std::string ErrMsg;
- raw_fd_ostream file(file_pathname.c_str(), ErrMsg,
- raw_fd_ostream::F_Binary);
+ raw_fd_ostream file(file_pathname.c_str(), ErrMsg, sys::fs::F_Binary);
ASSERT_FALSE(file.has_error());
StringRef magic(i->magic_str, i->magic_str_len);
file << magic;
Modified: llvm/trunk/utils/FileUpdate/FileUpdate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/FileUpdate/FileUpdate.cpp?rev=186447&r1=186446&r2=186447&view=diff
==============================================================================
--- llvm/trunk/utils/FileUpdate/FileUpdate.cpp (original)
+++ llvm/trunk/utils/FileUpdate/FileUpdate.cpp Tue Jul 16 14:44:17 2013
@@ -71,7 +71,7 @@ int main(int argc, char **argv) {
<< "', contents changed.\n";
std::string ErrorStr;
tool_output_file OutStream(OutputFilename.c_str(), ErrorStr,
- raw_fd_ostream::F_Binary);
+ sys::fs::F_Binary);
if (!ErrorStr.empty()) {
errs() << argv[0] << ": Unable to write output '"
<< OutputFilename << "': " << ErrorStr << '\n';
More information about the llvm-commits
mailing list