[llvm] r186381 - Use open+fstat instead of stat+open.
Rafael Espindola
rafael.espindola at gmail.com
Mon Jul 15 20:34:32 PDT 2013
Author: rafael
Date: Mon Jul 15 22:34:31 2013
New Revision: 186381
URL: http://llvm.org/viewvc/llvm-project?rev=186381&view=rev
Log:
Use open+fstat instead of stat+open.
Modified:
llvm/trunk/tools/llvm-ar/llvm-ar.cpp
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=186381&r1=186380&r2=186381&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Mon Jul 15 22:34:31 2013
@@ -555,13 +555,23 @@ static void performWriteOperation(Archiv
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();
More information about the llvm-commits
mailing list