Home | History | Annotate | Download | only in Support
      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, StringRef Program, const char **args,
     26                     const char **env, const StringRef **Redirects,
     27                     unsigned memoryLimit, std::string *ErrMsg);
     28 
     29 static int Wait(void *&Data, StringRef Program, unsigned secondsToWait,
     30                 std::string *ErrMsg);
     31 
     32 int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp,
     33                         const StringRef **redirects, unsigned secondsToWait,
     34                         unsigned memoryLimit, std::string *ErrMsg,
     35                         bool *ExecutionFailed) {
     36   void *Data = 0;
     37   if (Execute(&Data, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
     38     if (ExecutionFailed) *ExecutionFailed = false;
     39     return Wait(Data, Program, secondsToWait, ErrMsg);
     40   }
     41   if (ExecutionFailed) *ExecutionFailed = true;
     42   return -1;
     43 }
     44 
     45 void sys::ExecuteNoWait(StringRef Program, const char **args, const char **envp,
     46                         const StringRef **redirects, unsigned memoryLimit,
     47                         std::string *ErrMsg) {
     48   Execute(/*Data*/ 0, Program, args, envp, redirects, memoryLimit, ErrMsg);
     49 }
     50 
     51 // Include the platform-specific parts of this class.
     52 #ifdef LLVM_ON_UNIX
     53 #include "Unix/Program.inc"
     54 #endif
     55 #ifdef LLVM_ON_WIN32
     56 #include "Windows/Program.inc"
     57 #endif
     58