diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Bitcode/Writer/BitWriter.cpp | 2 | ||||
-rw-r--r-- | lib/CodeGen/MachineVerifier.cpp | 3 | ||||
-rw-r--r-- | lib/MC/MCParser/DarwinAsmParser.cpp | 2 | ||||
-rw-r--r-- | lib/Support/DataStream.cpp | 13 | ||||
-rw-r--r-- | lib/Support/MemoryBuffer.cpp | 12 | ||||
-rw-r--r-- | lib/Support/Path.cpp | 46 | ||||
-rw-r--r-- | lib/Support/Timer.cpp | 4 | ||||
-rw-r--r-- | lib/Support/ToolOutputFile.cpp | 5 | ||||
-rw-r--r-- | lib/Support/raw_ostream.cpp | 40 | ||||
-rw-r--r-- | lib/Target/TargetMachineC.cpp | 2 | ||||
-rw-r--r-- | lib/Transforms/Instrumentation/GCOVProfiling.cpp | 2 |
11 files changed, 71 insertions, 60 deletions
diff --git a/lib/Bitcode/Writer/BitWriter.cpp b/lib/Bitcode/Writer/BitWriter.cpp index 985208c40f..cd1ada22cf 100644 --- a/lib/Bitcode/Writer/BitWriter.cpp +++ b/lib/Bitcode/Writer/BitWriter.cpp @@ -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; diff --git a/lib/CodeGen/MachineVerifier.cpp b/lib/CodeGen/MachineVerifier.cpp index 4edb604456..e74bfc80d5 100644 --- a/lib/CodeGen/MachineVerifier.cpp +++ b/lib/CodeGen/MachineVerifier.cpp @@ -271,8 +271,7 @@ bool MachineVerifier::runOnMachineFunction(MachineFunction &MF) { 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); diff --git a/lib/MC/MCParser/DarwinAsmParser.cpp b/lib/MC/MCParser/DarwinAsmParser.cpp index 7eb8b74834..0aeeaf6cfa 100644 --- a/lib/MC/MCParser/DarwinAsmParser.cpp +++ b/lib/MC/MCParser/DarwinAsmParser.cpp @@ -593,7 +593,7 @@ bool DarwinAsmParser::ParseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) { 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: ") + diff --git a/lib/Support/DataStream.cpp b/lib/Support/DataStream.cpp index 7815d08092..0bd0c68702 100644 --- a/lib/Support/DataStream.cpp +++ b/lib/Support/DataStream.cpp @@ -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); } }; diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index a7553d1c96..be1d9c7874 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -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 char *Filename, 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); diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 69dd6f5a71..0fb7666aeb 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -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 Twine &Prefix, 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()); diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp index 896d869aa1..100b21e122 100644 --- a/lib/Support/Timer.cpp +++ b/lib/Support/Timer.cpp @@ -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; diff --git a/lib/Support/ToolOutputFile.cpp b/lib/Support/ToolOutputFile.cpp index 824e0a73d2..5c1268a40a 100644 --- a/lib/Support/ToolOutputFile.cpp +++ b/lib/Support/ToolOutputFile.cpp @@ -37,9 +37,8 @@ tool_output_file::CleanupInstaller::~CleanupInstaller() { } 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; diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp index 7609b916fb..3e5ce04d75 100644 --- a/lib/Support/raw_ostream.cpp +++ b/lib/Support/raw_ostream.cpp @@ -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 char *Filename, std::string &ErrorInfo, 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. diff --git a/lib/Target/TargetMachineC.cpp b/lib/Target/TargetMachineC.cpp index 01d12e8ba5..741912200d 100644 --- a/lib/Target/TargetMachineC.cpp +++ b/lib/Target/TargetMachineC.cpp @@ -200,7 +200,7 @@ static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M, 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()); diff --git a/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/lib/Transforms/Instrumentation/GCOVProfiling.cpp index 0f700ca909..408c61a4a2 100644 --- a/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -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); |