blob: 4213b84b8bde374dfe5c703c632804b3cc2ee6b8 [file] [log] [blame]
Misha Brukman4b585812004-06-18 15:38:49 +00001//===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
John Criswell482202a2003-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 Lattnerde4aa4c2002-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 Spencer7c16caa2004-09-01 22:55:40 +000015#include "llvm/Support/SystemUtils.h"
Reid Spencerdc49d862004-12-13 23:41:37 +000016#include "llvm/System/Program.h"
Reid Spencerc2e22fe2004-12-14 04:18:15 +000017
Chris Lattnerc9499b62003-12-14 21:35:53 +000018using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000019
Chris Lattner454e1832004-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 Gaeke5ade5012004-04-02 21:26:04 +000023#if HAVE_ISATTY
Chris Lattner454e1832004-04-02 05:04:03 +000024 return isatty(1);
Brian Gaeke5ade5012004-04-02 21:26:04 +000025#endif
26 // If we don't have isatty, just return false.
27 return false;
Chris Lattner454e1832004-04-02 05:04:03 +000028}
29
30
Misha Brukmane4d58ec2003-08-07 21:34:25 +000031/// FindExecutable - Find a named executable, giving the argv[0] of program
Misha Brukman34c96102003-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 Spencerd44f8452004-12-19 18:00:09 +000036///
Chris Lattnerb6d6b932004-05-28 01:20:58 +000037#undef FindExecutable // needed on windows :(
Reid Spencerdc49d862004-12-13 23:41:37 +000038sys::Path llvm::FindExecutable(const std::string &ExeName,
Reid Spencerd44f8452004-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 Spencerdc49d862004-12-13 23:41:37 +000041 // if ProgramPath contains at least one / character, indicating that it is a
Chris Lattnerde4aa4c2002-12-23 23:50:16 +000042 // relative path to bugpoint itself.
Reid Spencerdc49d862004-12-13 23:41:37 +000043 sys::Path Result ( ProgramPath );
44 Result.elideFile();
Reid Spencerdc49d862004-12-13 23:41:37 +000045 if (!Result.isEmpty()) {
46 Result.appendFile(ExeName);
Reid Spencerd44f8452004-12-19 18:00:09 +000047 if (Result.executable())
48 return Result;
Chris Lattnerde4aa4c2002-12-23 23:50:16 +000049 }
50
Reid Spencerdc49d862004-12-13 23:41:37 +000051 return sys::Program::FindProgramByName(ExeName);
Chris Lattnerde4aa4c2002-12-23 23:50:16 +000052}