Misha Brukman | ebb0faa | 2004-06-18 15:38:49 +0000 | [diff] [blame] | 1 | //===- SystemUtils.cpp - Utilities for low-level system tasks -------------===// |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 2 | // |
| 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 Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file contains functions used to do a variety of low-level, often |
| 11 | // system-specific, tasks. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 15 | #include "llvm/Support/SystemUtils.h" |
Reid Spencer | 9665e8a | 2004-12-13 23:41:37 +0000 | [diff] [blame] | 16 | #include "llvm/System/Program.h" |
Reid Spencer | 44f6966 | 2004-12-14 04:18:15 +0000 | [diff] [blame] | 17 | |
Chris Lattner | 2cdd21c | 2003-12-14 21:35:53 +0000 | [diff] [blame] | 18 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 19 | |
Chris Lattner | b234d46 | 2004-04-02 05:04:03 +0000 | [diff] [blame] | 20 | /// isStandardOutAConsole - Return true if we can tell that the standard output |
| 21 | /// stream goes to a terminal window or console. |
| 22 | bool llvm::isStandardOutAConsole() { |
Brian Gaeke | 8507ecb | 2004-04-02 21:26:04 +0000 | [diff] [blame] | 23 | #if HAVE_ISATTY |
Chris Lattner | b234d46 | 2004-04-02 05:04:03 +0000 | [diff] [blame] | 24 | return isatty(1); |
Brian Gaeke | 8507ecb | 2004-04-02 21:26:04 +0000 | [diff] [blame] | 25 | #endif |
| 26 | // If we don't have isatty, just return false. |
| 27 | return false; |
Chris Lattner | b234d46 | 2004-04-02 05:04:03 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | |
Misha Brukman | f7066c7 | 2003-08-07 21:34:25 +0000 | [diff] [blame] | 31 | /// FindExecutable - Find a named executable, giving the argv[0] of program |
Misha Brukman | 44f8a34 | 2003-09-29 22:40:07 +0000 | [diff] [blame] | 32 | /// 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 Spencer | a434805 | 2004-12-19 18:00:09 +0000 | [diff] [blame^] | 36 | /// |
Chris Lattner | 49f61c4 | 2004-05-28 01:20:58 +0000 | [diff] [blame] | 37 | #undef FindExecutable // needed on windows :( |
Reid Spencer | 9665e8a | 2004-12-13 23:41:37 +0000 | [diff] [blame] | 38 | sys::Path llvm::FindExecutable(const std::string &ExeName, |
Reid Spencer | a434805 | 2004-12-19 18:00:09 +0000 | [diff] [blame^] | 39 | const std::string &ProgramPath) { |
| 40 | // First check the directory that the calling program is in. We can do this |
Reid Spencer | 9665e8a | 2004-12-13 23:41:37 +0000 | [diff] [blame] | 41 | // if ProgramPath contains at least one / character, indicating that it is a |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 42 | // relative path to bugpoint itself. |
Reid Spencer | 9665e8a | 2004-12-13 23:41:37 +0000 | [diff] [blame] | 43 | sys::Path Result ( ProgramPath ); |
| 44 | Result.elideFile(); |
Reid Spencer | 9665e8a | 2004-12-13 23:41:37 +0000 | [diff] [blame] | 45 | if (!Result.isEmpty()) { |
| 46 | Result.appendFile(ExeName); |
Reid Spencer | a434805 | 2004-12-19 18:00:09 +0000 | [diff] [blame^] | 47 | if (Result.executable()) |
| 48 | return Result; |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Reid Spencer | 9665e8a | 2004-12-13 23:41:37 +0000 | [diff] [blame] | 51 | return sys::Program::FindProgramByName(ExeName); |
Chris Lattner | 4a10645 | 2002-12-23 23:50:16 +0000 | [diff] [blame] | 52 | } |