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
This commit is contained in:
Reid Spencer 2004-12-13 23:41:37 +00:00
parent 1749a0c1b9
commit 9665e8a697

View File

@ -12,16 +12,11 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#define _POSIX_MAPPED_FILES
#include "llvm/Support/SystemUtils.h" #include "llvm/Support/SystemUtils.h"
#include "llvm/Config/fcntl.h" #include "llvm/System/Program.h"
#include "llvm/Config/pagesize.h" #include <unistd.h>
#include "llvm/Config/unistd.h" #include <wait.h>
#include "llvm/Config/windows.h" #include <sys/fcntl.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 <algorithm> #include <algorithm>
#include <cerrno> #include <cerrno>
#include <cstdlib> #include <cstdlib>
@ -30,25 +25,6 @@
#include <signal.h> #include <signal.h>
using namespace llvm; 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 /// isStandardOutAConsole - Return true if we can tell that the standard output
/// stream goes to a terminal window or console. /// stream goes to a terminal window or console.
bool llvm::isStandardOutAConsole() { bool llvm::isStandardOutAConsole() {
@ -67,48 +43,21 @@ bool llvm::isStandardOutAConsole() {
/// empty string. /// empty string.
/// ///
#undef FindExecutable // needed on windows :( #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) { const std::string &ProgramPath) {
// First check the directory that bugpoint is in. We can do this if // First check the directory that the calling program is in. We can do this
// BugPointPath contains at least one / character, indicating that it is a // if ProgramPath contains at least one / character, indicating that it is a
// relative path to bugpoint itself. // relative path to bugpoint itself.
// //
std::string Result = ProgramPath; sys::Path Result ( ProgramPath );
while (!Result.empty() && Result[Result.size()-1] != '/') Result.elideFile();
Result.erase(Result.size()-1, 1);
if (!Result.empty()) { if (!Result.isEmpty()) {
Result += ExeName; Result.appendFile(ExeName);
if (isExecutableFile(Result)) return Result; // Found it? if (Result.executable()) return Result;
} }
// Okay, if the path to the program didn't tell us anything, try using the return sys::Program::FindProgramByName(ExeName);
// 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 we fell out, we ran out of directories in PATH to search, return failure
return "";
} }
static void RedirectFD(const std::string &File, int FD) { static void RedirectFD(const std::string &File, int FD) {