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(void **Data, const Path &path, const char **args,
26 const char **env, const sys::Path **redirects,
27 unsigned memoryLimit, std::string *ErrMsg);
29 static int Wait(void *&Data, const Path &path, unsigned secondsToWait,
32 int sys::ExecuteAndWait(StringRef path, const char **args, const char **env,
33 const StringRef **redirects, unsigned secondsToWait,
34 unsigned memoryLimit, std::string *ErrMsg,
35 bool *ExecutionFailed) {
38 return ExecuteAndWait(P, args, env, 0, secondsToWait, memoryLimit, ErrMsg,
42 for (int I = 0; I < 3; ++I) {
44 IO[I] = *redirects[I];
51 return ExecuteAndWait(P, args, env, IOP, secondsToWait, memoryLimit, ErrMsg,
55 int sys::ExecuteAndWait(const Path &path, const char **args, const char **envp,
56 const Path **redirects, unsigned secondsToWait,
57 unsigned memoryLimit, std::string *ErrMsg,
58 bool *ExecutionFailed) {
60 if (Execute(&Data, path, args, envp, redirects, memoryLimit, ErrMsg)) {
61 if (ExecutionFailed) *ExecutionFailed = false;
62 return Wait(Data, path, secondsToWait, ErrMsg);
64 if (ExecutionFailed) *ExecutionFailed = true;
68 void sys::ExecuteNoWait(const Path &path, const char **args, const char **envp,
69 const Path **redirects, unsigned memoryLimit,
70 std::string *ErrMsg) {
71 Execute(/*Data*/ 0, path, args, envp, redirects, memoryLimit, ErrMsg);
74 // Include the platform-specific parts of this class.
76 #include "Unix/Program.inc"
79 #include "Windows/Program.inc"