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 file implements the operating system Program concept.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/Program.h"
15 #include "llvm/Config/config.h"
16 #include <system_error>
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(
38 PI, secondsToWait, /*WaitUntilTerminates=*/secondsToWait == 0, ErrMsg);
39 return Result.ReturnCode;
43 *ExecutionFailed = true;
48 ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **args,
49 const char **envp, const StringRef **redirects,
50 unsigned memoryLimit, std::string *ErrMsg,
51 bool *ExecutionFailed) {
54 *ExecutionFailed = false;
55 if (!Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg))
57 *ExecutionFailed = true;
62 // Include the platform-specific parts of this class.
64 #include "Unix/Program.inc"
67 #include "Windows/Program.inc"