From: Benjamin Kramer Date: Sat, 2 Jun 2012 16:28:09 +0000 (+0000) Subject: Use access(2) instead of stat(2) to check if a file exists. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=1222c5c121e1284e37ae91b22a5b8bf6803b077f;p=oota-llvm.git Use access(2) instead of stat(2) to check if a file exists. Apart from being slightly cheaper, this fixes a real bug that hits 32 bit linux systems. When passing a file larger than 2G to be linked (which isn't that uncommon with large projects such as WebKit), clang's driver checks if the file exists but the file size doesn't fit in an off_t and stat(2) fails with EOVERFLOW. Clang then says that the file doesn't exist instead of passing it to the linker. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157891 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Support/Unix/PathV2.inc b/lib/Support/Unix/PathV2.inc index a7007cd6974..a5630b9ec90 100644 --- a/lib/Support/Unix/PathV2.inc +++ b/lib/Support/Unix/PathV2.inc @@ -273,8 +273,7 @@ error_code exists(const Twine &path, bool &result) { SmallString<128> path_storage; StringRef p = path.toNullTerminatedStringRef(path_storage); - struct stat status; - if (::stat(p.begin(), &status) == -1) { + if (::access(p.begin(), F_OK) == -1) { if (errno != errc::no_such_file_or_directory) return error_code(errno, system_category()); result = false;