From: Benjamin Kramer Date: Sun, 18 Oct 2009 11:19:36 +0000 (+0000) Subject: CIndex: replace fork/exec with our portable ExecuteAndWait wrapper. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0829a839b05c687d3f11af0640d84c5d05f94124;p=clang CIndex: replace fork/exec with our portable ExecuteAndWait wrapper. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84414 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index c262f67287..4ade9477c5 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -24,10 +24,10 @@ #include "clang/Frontend/ASTUnit.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/System/Path.h" +#include "llvm/System/Program.h" #include #ifndef _MSC_VER #include -#include #endif #include @@ -356,22 +356,8 @@ CXTranslationUnit clang_createTranslationUnitFromSourceFile( argv.push_back(NULL); // Generate the AST file in a separate process. - pid_t child_pid = fork(); - if (child_pid == 0) { // Child process - - // Execute the command, passing the appropriate arguments. - execv(argv[0], (char *const *)&argv[0]); - - // If execv returns, it failed. - assert(0 && "execv() failed"); - } - // This is run by the parent. - int child_status; - pid_t tpid; - do { // Wait for the child to terminate. - tpid = wait(&child_status); - } while (tpid != child_pid); - + llvm::sys::Program::ExecuteAndWait(llvm::sys::Path(argv[0]), &argv[0]); + // Finally, we create the translation unit from the ast file. ASTUnit *ATU = static_cast( clang_createTranslationUnit(CIdx, astTmpFile));