Use open+fstat instead of stat+open.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186381 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2013-07-16 03:34:31 +00:00
parent 289e241d77
commit bd6cb260b9

View File

@ -555,13 +555,23 @@ static void performWriteOperation(ArchiveOperation Operation,
printWithSpacePadding(Out, Name, 16); printWithSpacePadding(Out, Name, 16);
if (I->isNewMember()) { if (I->isNewMember()) {
// FIXME: we do a stat + open. We should do a open + fstat.
const char *FileName = I->getNew(); 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; sys::fs::file_status Status;
failIfError(sys::fs::status(FileName, Status), FileName); failIfError(sys::fs::status(FD, Status), FileName);
OwningPtr<MemoryBuffer> File; OwningPtr<MemoryBuffer> File;
failIfError(MemoryBuffer::getFile(FileName, File), FileName); failIfError(
MemoryBuffer::getOpenFile(FD, FileName, File, Status.getSize()),
FileName);
uint64_t secondsSinceEpoch = uint64_t secondsSinceEpoch =
Status.getLastModificationTime().toEpochTime(); Status.getLastModificationTime().toEpochTime();