1#ifndef CPPAD_CG_LINUX_SYSTEM_INCLUDED
2#define CPPAD_CG_LINUX_SYSTEM_INCLUDED
19#if CPPAD_CG_SYSTEM_LINUX
44 inline FDHandler() : fd(0), closed(true) {
47 inline explicit FDHandler(
int fd) : fd(fd), closed(false) {
71 inline void create() {
74 throw CGException(
"Failed to create pipe");
85#ifdef CPPAD_CG_SYSTEM_APPLE
87const std::string SystemInfo<T>::DYNAMIC_LIB_EXTENSION =
".dylib";
90const std::string SystemInfo<T>::DYNAMIC_LIB_EXTENSION =
".so";
94const std::string SystemInfo<T>::STATIC_LIB_EXTENSION =
".a";
96inline std::string getWorkingDirectory() {
100 if (
ret ==
nullptr) {
102 throw CGException(
"Failed to get current working directory: ",
error);
113 throw CGException(
"Failed to create directory '",
folder +
"': ",
error);
119 const std::string&
file) {
122 size_t n =
file.size();
142 const std::string&
file) {
147 return std::string(
"\"") +
path +
"\"";
150inline std::string filenameFromPath(
const std::string&
path) {
152 if (
pos != std::string::npos) {
163inline std::string directoryFromPath(
const std::string&
path) {
165 if (
found != std::string::npos) {
175 return path[0] ==
'/';
199 const std::vector<std::string>&
args,
221 throw CGException(
"Failed to fork process");
235 perror(
"redirecting stdin");
245 perror(
"redirecting stdout");
251 perror(
"redirecting stderr");
257 const size_t s =
args.size() + 1;
258 char*
args2 =
new char[s];
259 for (
size_t c = 0;
c < s - 1;
c++) {
266 std::vector<char*>
args2(
args.size() + 2);
268 for (
size_t i = 0;
i <
args.size();
i++) {
271 args2.back() = (
char *)
nullptr;
275 for (
size_t i = 0;
i <
args.size();
i++) {
285#ifndef CPPAD_CG_SYSTEM_APPLE
294 std::cerr <<
"Failed to send message to parent process" << std::endl;
296 std::cerr <<
"*** ERROR: exec failed" << std::endl;
315#ifndef CPPAD_CG_SYSTEM_APPLE
319 return std::string(
buf);
347 if (size > 1
e4)
break;
354 if (size > 1
e4)
break;
358 throw CGException(
"Waitpid failed for pid ",
pid,
" [",
readCErrorMsg(),
"]");
368 std::ostringstream s;
369 s <<
"Failed to write to pipe";
372 throw CGException(s.str());
377 std::ostringstream s;
380 throw CGException(s.str());
383 std::ostringstream s;
386 throw CGException(s.str());
bool isDirectory(const std::string &path)
bool isFile(const std::string &path)
std::string createPath(const std::string &baseFolder, const std::string &file)
void createFolder(const std::string &folder)
bool isAbsolutePath(const std::string &path)
std::string escapePath(const std::string &path)
void callExecutable(const std::string &executable, const std::vector< std::string > &args, std::string *stdOutErrMessage=nullptr, const std::string *stdInMessage=nullptr)
bool GreaterThanZero(const cg::CG< Base > &x)