2004-06-18 15:38:49 +00:00
|
|
|
//===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
|
2003-10-20 19:43:21 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2002-12-23 23:50:16 +00:00
|
|
|
//
|
|
|
|
// This file contains functions used to do a variety of low-level, often
|
|
|
|
// system-specific, tasks.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/Support/SystemUtils.h"
|
2004-12-13 23:41:37 +00:00
|
|
|
#include "llvm/System/Program.h"
|
2004-12-14 04:18:15 +00:00
|
|
|
|
2003-12-14 21:35:53 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2004-04-02 05:04:03 +00:00
|
|
|
/// isStandardOutAConsole - Return true if we can tell that the standard output
|
|
|
|
/// stream goes to a terminal window or console.
|
|
|
|
bool llvm::isStandardOutAConsole() {
|
2004-04-02 21:26:04 +00:00
|
|
|
#if HAVE_ISATTY
|
2004-04-02 05:04:03 +00:00
|
|
|
return isatty(1);
|
2004-04-02 21:26:04 +00:00
|
|
|
#endif
|
|
|
|
// If we don't have isatty, just return false.
|
|
|
|
return false;
|
2004-04-02 05:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-07 21:34:25 +00:00
|
|
|
/// FindExecutable - Find a named executable, giving the argv[0] of program
|
2003-09-29 22:40:07 +00:00
|
|
|
/// being executed. This allows us to find another LLVM tool if it is built
|
|
|
|
/// into the same directory, but that directory is neither the current
|
|
|
|
/// directory, nor in the PATH. If the executable cannot be found, return an
|
|
|
|
/// empty string.
|
2004-12-19 18:00:09 +00:00
|
|
|
///
|
2004-05-28 01:20:58 +00:00
|
|
|
#undef FindExecutable // needed on windows :(
|
2004-12-13 23:41:37 +00:00
|
|
|
sys::Path llvm::FindExecutable(const std::string &ExeName,
|
2004-12-19 18:00:09 +00:00
|
|
|
const std::string &ProgramPath) {
|
|
|
|
// First check the directory that the calling program is in. We can do this
|
2004-12-13 23:41:37 +00:00
|
|
|
// if ProgramPath contains at least one / character, indicating that it is a
|
2002-12-23 23:50:16 +00:00
|
|
|
// relative path to bugpoint itself.
|
2004-12-13 23:41:37 +00:00
|
|
|
sys::Path Result ( ProgramPath );
|
|
|
|
Result.elideFile();
|
|
|
|
if (!Result.isEmpty()) {
|
|
|
|
Result.appendFile(ExeName);
|
2004-12-19 18:00:09 +00:00
|
|
|
if (Result.executable())
|
|
|
|
return Result;
|
2002-12-23 23:50:16 +00:00
|
|
|
}
|
|
|
|
|
2004-12-13 23:41:37 +00:00
|
|
|
return sys::Program::FindProgramByName(ExeName);
|
2002-12-23 23:50:16 +00:00
|
|
|
}
|