1 //===-- Program.cpp - Implement OS Program Concept --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header file implements the operating system Program concept.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/Program.h"
15 #include "llvm/Config/config.h"
16 #include "llvm/Support/system_error.h"
20 //===----------------------------------------------------------------------===//
21 //=== WARNING: Implementation here must contain only TRULY operating system
22 //=== independent code.
23 //===----------------------------------------------------------------------===//
25 static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
26 const char **env, const StringRef **Redirects,
27 unsigned memoryLimit, std::string *ErrMsg);
29 int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp,
30 const StringRef **redirects, unsigned secondsToWait,
31 unsigned memoryLimit, std::string *ErrMsg,
32 bool *ExecutionFailed) {
34 if (Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
36 *ExecutionFailed = false;
37 ProcessInfo Result = Wait(PI, secondsToWait, true, ErrMsg);
38 return Result.ReturnCode;
42 *ExecutionFailed = true;
47 ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **args,
48 const char **envp, const StringRef **redirects,
49 unsigned memoryLimit, std::string *ErrMsg,
50 bool *ExecutionFailed) {
53 *ExecutionFailed = false;
54 if (!Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg))
56 *ExecutionFailed = true;
61 // Include the platform-specific parts of this class.
63 #include "Unix/Program.inc"
66 #include "Windows/Program.inc"