From: Rafael Espindola Date: Mon, 29 Jul 2013 18:22:23 +0000 (+0000) Subject: Convert a use of stat with sys::fs::status. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aefb1d3312a63ac8d289a2e84747fe61a7f61823;p=clang Convert a use of stat with sys::fs::status. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187364 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/FileManager.h b/include/clang/Basic/FileManager.h index ebf9b497f7..99fa5fa1cd 100644 --- a/include/clang/Basic/FileManager.h +++ b/include/clang/Basic/FileManager.h @@ -24,6 +24,7 @@ #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Allocator.h" +#include "llvm/Support/FileSystem.h" // FIXME: Enhance libsystem to support inode and other fields in stat. #include @@ -243,7 +244,8 @@ public: /// /// If the path is relative, it will be resolved against the WorkingDir of the /// FileManager's FileSystemOptions. - bool getNoncachedStatValue(StringRef Path, struct stat &StatBuf); + bool getNoncachedStatValue(StringRef Path, + llvm::sys::fs::file_status &Result); /// \brief Remove the real file \p Entry from the cache. void invalidateCache(const FileEntry *Entry); diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp index 651a7a430a..079b7fffb6 100644 --- a/lib/Basic/FileManager.cpp +++ b/lib/Basic/FileManager.cpp @@ -587,12 +587,12 @@ bool FileManager::getStatValue(const char *Path, struct stat &StatBuf, isFile, FileDescriptor, StatCache.get()); } -bool FileManager::getNoncachedStatValue(StringRef Path, - struct stat &StatBuf) { +bool FileManager::getNoncachedStatValue(StringRef Path, + llvm::sys::fs::file_status &Result) { SmallString<128> FilePath(Path); FixupRelativePath(FilePath); - return ::stat(FilePath.c_str(), &StatBuf) != 0; + return llvm::sys::fs::status(FilePath.c_str(), Result); } void FileManager::invalidateCache(const FileEntry *Entry) { diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 9251fc0daa..909186118f 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -1417,16 +1417,16 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( REnd = PreprocessorOpts.remapped_file_end(); !AnyFileChanged && R != REnd; ++R) { - struct stat StatBuf; - if (FileMgr->getNoncachedStatValue(R->second, StatBuf)) { + llvm::sys::fs::file_status Status; + if (FileMgr->getNoncachedStatValue(R->second, Status)) { // If we can't stat the file we're remapping to, assume that something // horrible happened. AnyFileChanged = true; break; } - - OverriddenFiles[R->first] = std::make_pair(StatBuf.st_size, - StatBuf.st_mtime); + + OverriddenFiles[R->first] = std::make_pair( + Status.getSize(), Status.getLastModificationTime().toEpochTime()); } for (PreprocessorOptions::remapped_file_buffer_iterator R = PreprocessorOpts.remapped_file_buffer_begin(), @@ -1455,12 +1455,13 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( } // The file was not remapped; check whether it has changed on disk. - struct stat StatBuf; - if (FileMgr->getNoncachedStatValue(F->first(), StatBuf)) { + llvm::sys::fs::file_status Status; + if (FileMgr->getNoncachedStatValue(F->first(), Status)) { // If we can't stat the file, assume that something horrible happened. AnyFileChanged = true; - } else if (StatBuf.st_size != F->second.first || - StatBuf.st_mtime != F->second.second) + } else if (Status.getSize() != uint64_t(F->second.first) || + Status.getLastModificationTime().toEpochTime() != + uint64_t(F->second.second)) AnyFileChanged = true; }