LLVM API Documentation

Program.cpp
Go to the documentation of this file.
00001 //===-- Program.cpp - Implement OS Program Concept --------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file implements the operating system Program concept.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Support/Program.h"
00015 #include "llvm/Config/config.h"
00016 #include <system_error>
00017 using namespace llvm;
00018 using namespace sys;
00019 
00020 //===----------------------------------------------------------------------===//
00021 //=== WARNING: Implementation here must contain only TRULY operating system
00022 //===          independent code.
00023 //===----------------------------------------------------------------------===//
00024 
00025 static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
00026                     const char **env, const StringRef **Redirects,
00027                     unsigned memoryLimit, std::string *ErrMsg);
00028 
00029 int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp,
00030                         const StringRef **redirects, unsigned secondsToWait,
00031                         unsigned memoryLimit, std::string *ErrMsg,
00032                         bool *ExecutionFailed) {
00033   ProcessInfo PI;
00034   if (Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
00035     if (ExecutionFailed)
00036       *ExecutionFailed = false;
00037     ProcessInfo Result = Wait(
00038         PI, secondsToWait, /*WaitUntilTerminates=*/secondsToWait == 0, ErrMsg);
00039     return Result.ReturnCode;
00040   }
00041 
00042   if (ExecutionFailed)
00043     *ExecutionFailed = true;
00044 
00045   return -1;
00046 }
00047 
00048 ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **args,
00049                                const char **envp, const StringRef **redirects,
00050                                unsigned memoryLimit, std::string *ErrMsg,
00051                                bool *ExecutionFailed) {
00052   ProcessInfo PI;
00053   if (ExecutionFailed)
00054     *ExecutionFailed = false;
00055   if (!Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg))
00056     if (ExecutionFailed)
00057       *ExecutionFailed = true;
00058 
00059   return PI;
00060 }
00061 
00062 // Include the platform-specific parts of this class.
00063 #ifdef LLVM_ON_UNIX
00064 #include "Unix/Program.inc"
00065 #endif
00066 #ifdef LLVM_ON_WIN32
00067 #include "Windows/Program.inc"
00068 #endif