For PR351:
authorReid Spencer <rspencer@reidspencer.com>
Tue, 14 Dec 2004 04:18:51 +0000 (04:18 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Tue, 14 Dec 2004 04:18:51 +0000 (04:18 +0000)
Implement the new environment pointer for ExecuteAndWait

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18928 91177308-0d34-0410-b5e6-96231b3b80d8

lib/System/Unix/Program.cpp
lib/System/Unix/Program.inc
lib/System/Win32/Program.cpp
lib/System/Win32/Program.inc

index ae53720d1d847f944fc30948a2c4868800cc5cc2..35192ce7be2b91d6a063eec24081407dbe8f7d8a 100644 (file)
@@ -79,7 +79,8 @@ Program::FindProgramByName(const std::string& progName) {
 //
 int 
 Program::ExecuteAndWait(const Path& path, 
-                        const std::vector<std::string>& args) {
+                        const std::vector<std::string>& args,
+                        const char ** envp ) {
   if (!path.executable())
     throw path.toString() + " is not executable"; 
 
@@ -103,11 +104,15 @@ Program::ExecuteAndWait(const Path& path,
       break;
 
     // Child process: Execute the program.
-    case 0:
-      execve (path.c_str(), (char** const)argv, environ);
+    case 0: {
+      char** env = environ;
+      if (envp != 0)
+        env = (char**) envp;
+      execve (path.c_str(), (char** const)argv, env);
       // If the execve() failed, we should exit and let the parent pick up
       // our non-zero exit status.
       exit (errno);
+    }
 
     // Parent process: Break out of the switch to do our processing.
     default:
index ae53720d1d847f944fc30948a2c4868800cc5cc2..35192ce7be2b91d6a063eec24081407dbe8f7d8a 100644 (file)
@@ -79,7 +79,8 @@ Program::FindProgramByName(const std::string& progName) {
 //
 int 
 Program::ExecuteAndWait(const Path& path, 
-                        const std::vector<std::string>& args) {
+                        const std::vector<std::string>& args,
+                        const char ** envp ) {
   if (!path.executable())
     throw path.toString() + " is not executable"; 
 
@@ -103,11 +104,15 @@ Program::ExecuteAndWait(const Path& path,
       break;
 
     // Child process: Execute the program.
-    case 0:
-      execve (path.c_str(), (char** const)argv, environ);
+    case 0: {
+      char** env = environ;
+      if (envp != 0)
+        env = (char**) envp;
+      execve (path.c_str(), (char** const)argv, env);
       // If the execve() failed, we should exit and let the parent pick up
       // our non-zero exit status.
       exit (errno);
+    }
 
     // Parent process: Break out of the switch to do our processing.
     default:
index d6bd86ad2d34c67ecbee1f17ab22c92d4d84497f..4aff5e969c81315c68acde80cd6306fdd9a6dbdb 100644 (file)
@@ -69,7 +69,8 @@ Program::FindProgramByName(const std::string& progName) {
 //
 int 
 Program::ExecuteAndWait(const Path& path, 
-                        const std::vector<std::string>& args) {
+                        const std::vector<std::string>& args,
+                        const char** env) {
   if (!path.executable())
     throw path.toString() + " is not executable"; 
 
@@ -124,8 +125,9 @@ Program::ExecuteAndWait(const Path& path,
   PROCESS_INFORMATION pi;
   memset(&pi, 0, sizeof(pi));
 
+  LPVOID lpEnvironment = envp;
   if (!CreateProcess(path.c_str(), command, NULL, NULL, FALSE, 0,
-                     NULL, NULL, &si, &pi))
+                     lpEnvironment, NULL, &si, &pi))
   {
     ThrowError(std::string("Couldn't execute program '") + 
                path.toString() + "'");
index d6bd86ad2d34c67ecbee1f17ab22c92d4d84497f..4aff5e969c81315c68acde80cd6306fdd9a6dbdb 100644 (file)
@@ -69,7 +69,8 @@ Program::FindProgramByName(const std::string& progName) {
 //
 int 
 Program::ExecuteAndWait(const Path& path, 
-                        const std::vector<std::string>& args) {
+                        const std::vector<std::string>& args,
+                        const char** env) {
   if (!path.executable())
     throw path.toString() + " is not executable"; 
 
@@ -124,8 +125,9 @@ Program::ExecuteAndWait(const Path& path,
   PROCESS_INFORMATION pi;
   memset(&pi, 0, sizeof(pi));
 
+  LPVOID lpEnvironment = envp;
   if (!CreateProcess(path.c_str(), command, NULL, NULL, FALSE, 0,
-                     NULL, NULL, &si, &pi))
+                     lpEnvironment, NULL, &si, &pi))
   {
     ThrowError(std::string("Couldn't execute program '") + 
                path.toString() + "'");