summaryrefslogtreecommitdiff
path: root/lib/Support/Unix/PathV2.inc
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-06-17 10:48:34 +0000
committerManuel Klimek <klimek@google.com>2013-06-17 10:48:34 +0000
commitb30614a1dea947246a06f74c8b56d7cda4885aec (patch)
treeb00b1c84b77537e4c8260735f1b193935051b4a8 /lib/Support/Unix/PathV2.inc
parent7338de37a802970857079b5a532c5dd50d0a6d5d (diff)
downloadllvm-b30614a1dea947246a06f74c8b56d7cda4885aec.tar.gz
llvm-b30614a1dea947246a06f74c8b56d7cda4885aec.tar.bz2
llvm-b30614a1dea947246a06f74c8b56d7cda4885aec.tar.xz
Fix incorrectly finding 'executable' directories instead of files.
This broke for example the 'not' utility, if a directory called 'FileCheck' is executable and in the path before the actual 'FileCheck'. This patch steals the implementation of the "old" PathV1 canExecute implementation: - checks for R_OK (file readable): this is necessary for executing scripts; we should not regress here unless we have good reasons - checks for S_ISREG; if we want to get rid of this, we'd need to change all callers who already made the assumption when depending on Path V1. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184074 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Unix/PathV2.inc')
-rw-r--r--lib/Support/Unix/PathV2.inc9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/Support/Unix/PathV2.inc b/lib/Support/Unix/PathV2.inc
index df8841220b..68c17d534c 100644
--- a/lib/Support/Unix/PathV2.inc
+++ b/lib/Support/Unix/PathV2.inc
@@ -296,7 +296,14 @@ bool can_execute(const Twine &Path) {
SmallString<128> PathStorage;
StringRef P = Path.toNullTerminatedStringRef(PathStorage);
- return ::access(P.begin(), X_OK) != -1;
+ if (0 != access(P.begin(), R_OK | X_OK))
+ return false;
+ struct stat buf;
+ if (0 != stat(P.begin(), &buf))
+ return false;
+ if (!S_ISREG(buf.st_mode))
+ return false;
+ return true;
}
bool equivalent(file_status A, file_status B) {