1 //===-- Program.cpp - Implement OS Program Concept --------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This header file implements the operating system Program concept. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm/Support/Program.h" 15 #include "llvm/Config/config.h" 16 #include "llvm/Support/system_error.h" 17 using namespace llvm; 18 using namespace sys; 19 20 //===----------------------------------------------------------------------===// 21 //=== WARNING: Implementation here must contain only TRULY operating system 22 //=== independent code. 23 //===----------------------------------------------------------------------===// 24 25 static bool Execute(void *&Data, const Path &path, const char **args, 26 const char **env, const sys::Path **redirects, 27 unsigned memoryLimit, std::string *ErrMsg); 28 29 static int Wait(void *&Data, const Path &path, unsigned secondsToWait, 30 std::string *ErrMsg); 31 32 int sys::ExecuteAndWait(const Path &path, const char **args, const char **envp, 33 const Path **redirects, unsigned secondsToWait, 34 unsigned memoryLimit, std::string *ErrMsg, 35 bool *ExecutionFailed) { 36 void *Data = 0; 37 if (Execute(Data, path, args, envp, redirects, memoryLimit, ErrMsg)) { 38 if (ExecutionFailed) *ExecutionFailed = false; 39 return Wait(Data, path, secondsToWait, ErrMsg); 40 } 41 if (ExecutionFailed) *ExecutionFailed = true; 42 return -1; 43 } 44 45 void sys::ExecuteNoWait(const Path &path, const char **args, const char **envp, 46 const Path **redirects, unsigned memoryLimit, 47 std::string *ErrMsg) { 48 void *Data = 0; 49 Execute(Data, path, args, envp, redirects, memoryLimit, ErrMsg); 50 } 51 52 // Include the platform-specific parts of this class. 53 #ifdef LLVM_ON_UNIX 54 #include "Unix/Program.inc" 55 #endif 56 #ifdef LLVM_ON_WIN32 57 #include "Windows/Program.inc" 58 #endif 59