diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-16 19:44:17 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-16 19:44:17 +0000 |
commit | c1b49b56d4132efa2e06deb8f23508d0de4c8800 (patch) | |
tree | ac30ab59f60f12465f5b7ffd0823b08a711770e8 /tools/llvm-ar | |
parent | 1a9c39e52a2b1ce474dec773e77d12ae4c335a71 (diff) | |
download | llvm-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/llvm-ar')
-rw-r--r-- | tools/llvm-ar/llvm-ar.cpp | 25 |
1 files changed, 7 insertions, 18 deletions
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); |