LowerBitSets.cpp: Prune incorrect \param(s). [-Wdocumentation]
[oota-llvm.git] / lib / Support / Program.cpp
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 file implements the operating system Program concept.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Support/Program.h"
15 #include "llvm/Config/config.h"
16 #include <system_error>
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(ProcessInfo &PI, StringRef Program, const char **args,
26                     const char **env, const StringRef **Redirects,
27                     unsigned memoryLimit, std::string *ErrMsg);
28
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) {
33   ProcessInfo PI;
34   if (Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
35     if (ExecutionFailed)
36       *ExecutionFailed = false;
37     ProcessInfo Result = Wait(
38         PI, secondsToWait, /*WaitUntilTerminates=*/secondsToWait == 0, ErrMsg);
39     return Result.ReturnCode;
40   }
41
42   if (ExecutionFailed)
43     *ExecutionFailed = true;
44
45   return -1;
46 }
47
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) {
52   ProcessInfo PI;
53   if (ExecutionFailed)
54     *ExecutionFailed = false;
55   if (!Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg))
56     if (ExecutionFailed)
57       *ExecutionFailed = true;
58
59   return PI;
60 }
61
62 // Include the platform-specific parts of this class.
63 #ifdef LLVM_ON_UNIX
64 #include "Unix/Program.inc"
65 #endif
66 #ifdef LLVM_ON_WIN32
67 #include "Windows/Program.inc"
68 #endif