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/ADT/StringRef.h"
16 #include "llvm/Config/config.h"
17 #include <system_error>
21 //===----------------------------------------------------------------------===//
22 //=== WARNING: Implementation here must contain only TRULY operating system
23 //=== independent code.
24 //===----------------------------------------------------------------------===//
26 static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
27 const char **env, const StringRef **Redirects,
28 unsigned memoryLimit, std::string *ErrMsg);
30 int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp,
31 const StringRef **redirects, unsigned secondsToWait,
32 unsigned memoryLimit, std::string *ErrMsg,
33 bool *ExecutionFailed) {
35 if (Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
37 *ExecutionFailed = false;
38 ProcessInfo Result = Wait(
39 PI, secondsToWait, /*WaitUntilTerminates=*/secondsToWait == 0, ErrMsg);
40 return Result.ReturnCode;
44 *ExecutionFailed = true;
49 ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **args,
50 const char **envp, const StringRef **redirects,
51 unsigned memoryLimit, std::string *ErrMsg,
52 bool *ExecutionFailed) {
55 *ExecutionFailed = false;
56 if (!Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg))
58 *ExecutionFailed = true;
63 // Include the platform-specific parts of this class.
65 #include "Unix/Program.inc"
68 #include "Windows/Program.inc"