summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix
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
commit52772bf35600fd6df26523576ea429adc24766f4 (patch)
tree2ac2ba9e59183334899f84d8a2fb6686ab82a79c /llvm/lib/Support/Unix
parente4fb3dc7d47d5cc859adbf6b87191559bbfd8443 (diff)
downloadbcm5719-llvm-52772bf35600fd6df26523576ea429adc24766f4.tar.gz
bcm5719-llvm-52772bf35600fd6df26523576ea429adc24766f4.zip
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. llvm-svn: 184074
Diffstat (limited to 'llvm/lib/Support/Unix')
-rw-r--r--llvm/lib/Support/Unix/PathV2.inc9
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/Support/Unix/PathV2.inc b/llvm/lib/Support/Unix/PathV2.inc
index df8841220b5..68c17d534cd 100644
--- a/llvm/lib/Support/Unix/PathV2.inc
+++ b/llvm/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) {
OpenPOWER on IntegriCloud