summaryrefslogtreecommitdiff
path: root/lib/Support/SystemUtils.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-12-13 23:41:37 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-12-13 23:41:37 +0000
commit9665e8a697d1fa91aeca17f13a81dd2de2f11aa5 (patch)
tree500d608913c5e41eb8670eb2485be183b77f250d /lib/Support/SystemUtils.cpp
parent1749a0c1b9a17fd6b11fad2f6e6b66ab90eac4b4 (diff)
downloadllvm-9665e8a697d1fa91aeca17f13a81dd2de2f11aa5.tar.gz
llvm-9665e8a697d1fa91aeca17f13a81dd2de2f11aa5.tar.bz2
llvm-9665e8a697d1fa91aeca17f13a81dd2de2f11aa5.tar.xz
For PR351:
* Remove isExecutable as its now implemented by sys::Path::executable * Make FindExecutable a thin veneer over sys::Program::FindProgramByName. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18918 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/SystemUtils.cpp')
-rw-r--r--lib/Support/SystemUtils.cpp77
1 files changed, 13 insertions, 64 deletions
diff --git a/lib/Support/SystemUtils.cpp b/lib/Support/SystemUtils.cpp
index ba43306e8e..2538c0e3cd 100644
--- a/lib/Support/SystemUtils.cpp
+++ b/lib/Support/SystemUtils.cpp
@@ -12,16 +12,11 @@
//
//===----------------------------------------------------------------------===//
-#define _POSIX_MAPPED_FILES
#include "llvm/Support/SystemUtils.h"
-#include "llvm/Config/fcntl.h"
-#include "llvm/Config/pagesize.h"
-#include "llvm/Config/unistd.h"
-#include "llvm/Config/windows.h"
-#include "llvm/Config/sys/mman.h"
-#include "llvm/Config/sys/stat.h"
-#include "llvm/Config/sys/types.h"
-#include "llvm/Config/sys/wait.h"
+#include "llvm/System/Program.h"
+#include <unistd.h>
+#include <wait.h>
+#include <sys/fcntl.h>
#include <algorithm>
#include <cerrno>
#include <cstdlib>
@@ -30,25 +25,6 @@
#include <signal.h>
using namespace llvm;
-/// isExecutableFile - This function returns true if the filename specified
-/// exists and is executable.
-///
-bool llvm::isExecutableFile(const std::string &ExeFileName) {
- struct stat Buf;
- if (stat(ExeFileName.c_str(), &Buf))
- return false; // Must not be executable!
-
- if (!(Buf.st_mode & S_IFREG))
- return false; // Not a regular file?
-
- if (Buf.st_uid == getuid()) // Owner of file?
- return Buf.st_mode & S_IXUSR;
- else if (Buf.st_gid == getgid()) // In group of file?
- return Buf.st_mode & S_IXGRP;
- else // Unrelated to file?
- return Buf.st_mode & S_IXOTH;
-}
-
/// isStandardOutAConsole - Return true if we can tell that the standard output
/// stream goes to a terminal window or console.
bool llvm::isStandardOutAConsole() {
@@ -67,48 +43,21 @@ bool llvm::isStandardOutAConsole() {
/// empty string.
///
#undef FindExecutable // needed on windows :(
-std::string llvm::FindExecutable(const std::string &ExeName,
+sys::Path llvm::FindExecutable(const std::string &ExeName,
const std::string &ProgramPath) {
- // First check the directory that bugpoint is in. We can do this if
- // BugPointPath contains at least one / character, indicating that it is a
+ // First check the directory that the calling program is in. We can do this
+ // if ProgramPath contains at least one / character, indicating that it is a
// relative path to bugpoint itself.
//
- std::string Result = ProgramPath;
- while (!Result.empty() && Result[Result.size()-1] != '/')
- Result.erase(Result.size()-1, 1);
+ sys::Path Result ( ProgramPath );
+ Result.elideFile();
- if (!Result.empty()) {
- Result += ExeName;
- if (isExecutableFile(Result)) return Result; // Found it?
- }
-
- // Okay, if the path to the program didn't tell us anything, try using the
- // PATH environment variable.
- const char *PathStr = getenv("PATH");
- if (PathStr == 0) return "";
-
- // Now we have a colon separated list of directories to search... try them...
- unsigned PathLen = strlen(PathStr);
- while (PathLen) {
- // Find the first colon...
- const char *Colon = std::find(PathStr, PathStr+PathLen, ':');
-
- // Check to see if this first directory contains the executable...
- std::string FilePath = std::string(PathStr, Colon) + '/' + ExeName;
- if (isExecutableFile(FilePath))
- return FilePath; // Found the executable!
-
- // Nope it wasn't in this directory, check the next range!
- PathLen -= Colon-PathStr;
- PathStr = Colon;
- while (*PathStr == ':') { // Advance past colons
- PathStr++;
- PathLen--;
- }
+ if (!Result.isEmpty()) {
+ Result.appendFile(ExeName);
+ if (Result.executable()) return Result;
}
- // If we fell out, we ran out of directories in PATH to search, return failure
- return "";
+ return sys::Program::FindProgramByName(ExeName);
}
static void RedirectFD(const std::string &File, int FD) {