summaryrefslogtreecommitdiff
path: root/lib/Support/Unix
diff options
context:
space:
mode:
authorSylvestre Ledru <sylvestre@debian.org>2013-12-09 16:27:00 +0000
committerSylvestre Ledru <sylvestre@debian.org>2013-12-09 16:27:00 +0000
commit1a803295d08f1d562b4cebcb830edd874ec16d79 (patch)
treef651a1bd0495efbd1d3d316fe2c5c977d28ad7c6 /lib/Support/Unix
parent68138dc9a89cda52bdc7d27bbebec194809e93cf (diff)
downloadllvm-1a803295d08f1d562b4cebcb830edd874ec16d79.tar.gz
llvm-1a803295d08f1d562b4cebcb830edd874ec16d79.tar.bz2
llvm-1a803295d08f1d562b4cebcb830edd874ec16d79.tar.xz
Improve the detection of the path
Summary: When clang is used under GNU/Linux in a chroot without /proc mount, it falls back on the BSD method. However, since the buf variable is used twice and fails with snprintf to produce the correct path. When called as relatived (ie ./clang), it was failing with: "" -cc1 [...] -x c++ x.cc error: unable to execute command: Executable "" doesn't exist! I also took the opportunity to simply the code (the first arg of test_dir was useless). Reviewers: rafael Reviewed By: rafael CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D2361 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196791 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Unix')
-rw-r--r--lib/Support/Unix/Path.inc23
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc
index 6e08c63c1f..734ea5d110 100644
--- a/lib/Support/Unix/Path.inc
+++ b/lib/Support/Unix/Path.inc
@@ -184,15 +184,15 @@ namespace fs {
defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__) || \
defined(__linux__) || defined(__CYGWIN__) || defined(__DragonFly__)
static int
-test_dir(char buf[PATH_MAX], char ret[PATH_MAX],
- const char *dir, const char *bin)
-{
+test_dir(char ret[PATH_MAX], const char *dir, const char *bin)
+{
struct stat sb;
+ char fullpath[PATH_MAX];
- snprintf(buf, PATH_MAX, "%s/%s", dir, bin);
- if (realpath(buf, ret) == NULL)
+ snprintf(fullpath, PATH_MAX, "%s/%s", dir, bin);
+ if (realpath(fullpath, ret) == NULL)
return (1);
- if (stat(buf, &sb) != 0)
+ if (stat(fullpath, &sb) != 0)
return (1);
return (0);
@@ -201,20 +201,21 @@ test_dir(char buf[PATH_MAX], char ret[PATH_MAX],
static char *
getprogpath(char ret[PATH_MAX], const char *bin)
{
- char *pv, *s, *t, buf[PATH_MAX];
+ char *pv, *s, *t;
/* First approach: absolute path. */
if (bin[0] == '/') {
- if (test_dir(buf, ret, "/", bin) == 0)
+ if (test_dir(ret, "/", bin) == 0)
return (ret);
return (NULL);
}
/* Second approach: relative path. */
if (strchr(bin, '/') != NULL) {
- if (getcwd(buf, PATH_MAX) == NULL)
+ char cwd[PATH_MAX];
+ if (getcwd(cwd, PATH_MAX) == NULL)
return (NULL);
- if (test_dir(buf, ret, buf, bin) == 0)
+ if (test_dir(ret, cwd, bin) == 0)
return (ret);
return (NULL);
}
@@ -226,7 +227,7 @@ getprogpath(char ret[PATH_MAX], const char *bin)
if (pv == NULL)
return (NULL);
while ((t = strsep(&s, ":")) != NULL) {
- if (test_dir(buf, ret, t, bin) == 0) {
+ if (test_dir(ret, t, bin) == 0) {
free(pv);
return (ret);
}