diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-16 03:34:31 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-16 03:34:31 +0000 |
commit | bd6cb260b9ff3258c8855edcd31adffd6c7deb56 (patch) | |
tree | ad01c1978e804ade3afa8ce43432664ce127ae25 /tools/llvm-ar | |
parent | 289e241d775565b450286a682d7e8a1a1b625f61 (diff) | |
download | external_llvm-bd6cb260b9ff3258c8855edcd31adffd6c7deb56.zip external_llvm-bd6cb260b9ff3258c8855edcd31adffd6c7deb56.tar.gz external_llvm-bd6cb260b9ff3258c8855edcd31adffd6c7deb56.tar.bz2 |
Use open+fstat instead of stat+open.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186381 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-ar')
-rw-r--r-- | tools/llvm-ar/llvm-ar.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index e082687..32bcb49 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -555,13 +555,23 @@ static void performWriteOperation(ArchiveOperation Operation, printWithSpacePadding(Out, Name, 16); if (I->isNewMember()) { - // FIXME: we do a stat + open. We should do a open + fstat. 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); + sys::fs::file_status Status; - failIfError(sys::fs::status(FileName, Status), FileName); + failIfError(sys::fs::status(FD, Status), FileName); OwningPtr<MemoryBuffer> File; - failIfError(MemoryBuffer::getFile(FileName, File), FileName); + failIfError( + MemoryBuffer::getOpenFile(FD, FileName, File, Status.getSize()), + FileName); uint64_t secondsSinceEpoch = Status.getLastModificationTime().toEpochTime(); |