blob: 4213b84b8bde374dfe5c703c632804b3cc2ee6b8 [file] [log] [blame]
Misha Brukmanebb0faa2004-06-18 15:38:49 +00001//===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
John Criswellb576c942003-10-20 19:43:21 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Chris Lattner4a106452002-12-23 23:50:16 +00009//
10// This file contains functions used to do a variety of low-level, often
11// system-specific, tasks.
12//
13//===----------------------------------------------------------------------===//
14
Reid Spencer551ccae2004-09-01 22:55:40 +000015#include "llvm/Support/SystemUtils.h"
Reid Spencer9665e8a2004-12-13 23:41:37 +000016#include "llvm/System/Program.h"
Reid Spencer44f69662004-12-14 04:18:15 +000017
Chris Lattner2cdd21c2003-12-14 21:35:53 +000018using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000019
Chris Lattnerb234d462004-04-02 05:04:03 +000020/// isStandardOutAConsole - Return true if we can tell that the standard output
21/// stream goes to a terminal window or console.
22bool llvm::isStandardOutAConsole() {
Brian Gaeke8507ecb2004-04-02 21:26:04 +000023#if HAVE_ISATTY
Chris Lattnerb234d462004-04-02 05:04:03 +000024 return isatty(1);
Brian Gaeke8507ecb2004-04-02 21:26:04 +000025#endif
26 // If we don't have isatty, just return false.
27 return false;
Chris Lattnerb234d462004-04-02 05:04:03 +000028}
29
30
Misha Brukmanf7066c72003-08-07 21:34:25 +000031/// FindExecutable - Find a named executable, giving the argv[0] of program
Misha Brukman44f8a342003-09-29 22:40:07 +000032/// being executed. This allows us to find another LLVM tool if it is built
33/// into the same directory, but that directory is neither the current
34/// directory, nor in the PATH. If the executable cannot be found, return an
35/// empty string.
Reid Spencera4348052004-12-19 18:00:09 +000036///
Chris Lattner49f61c42004-05-28 01:20:58 +000037#undef FindExecutable // needed on windows :(
Reid Spencer9665e8a2004-12-13 23:41:37 +000038sys::Path llvm::FindExecutable(const std::string &ExeName,
Reid Spencera4348052004-12-19 18:00:09 +000039 const std::string &ProgramPath) {
40 // First check the directory that the calling program is in. We can do this
Reid Spencer9665e8a2004-12-13 23:41:37 +000041 // if ProgramPath contains at least one / character, indicating that it is a
Chris Lattner4a106452002-12-23 23:50:16 +000042 // relative path to bugpoint itself.
Reid Spencer9665e8a2004-12-13 23:41:37 +000043 sys::Path Result ( ProgramPath );
44 Result.elideFile();
Reid Spencer9665e8a2004-12-13 23:41:37 +000045 if (!Result.isEmpty()) {
46 Result.appendFile(ExeName);
Reid Spencera4348052004-12-19 18:00:09 +000047 if (Result.executable())
48 return Result;
Chris Lattner4a106452002-12-23 23:50:16 +000049 }
50
Reid Spencer9665e8a2004-12-13 23:41:37 +000051 return sys::Program::FindProgramByName(ExeName);
Chris Lattner4a106452002-12-23 23:50:16 +000052}