summaryrefslogtreecommitdiff
path: root/lib/System/Win32/Program.inc
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-06-15 03:54:39 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-06-15 03:54:39 +0000
commitf1844d2f58d3c6ea4e99329450bb46c0f054b232 (patch)
treeb04a234181007845bcee2ef8de6ebf5d042a296a /lib/System/Win32/Program.inc
parent184a876ee61dbbd602597f35e18240a5df8f5ee4 (diff)
downloadllvm-f1844d2f58d3c6ea4e99329450bb46c0f054b232.tar.gz
llvm-f1844d2f58d3c6ea4e99329450bb46c0f054b232.tar.bz2
llvm-f1844d2f58d3c6ea4e99329450bb46c0f054b232.tar.xz
Fix the environment block that is passed to the CreateProcess function.
This bug made llvm-ld unable to function with "-native" option, since the process that was used to call 'gcc' was crashing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52284 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Win32/Program.inc')
-rw-r--r--lib/System/Win32/Program.inc29
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/System/Win32/Program.inc b/lib/System/Win32/Program.inc
index 7e97c7fb4a..f2f101fa7b 100644
--- a/lib/System/Win32/Program.inc
+++ b/lib/System/Win32/Program.inc
@@ -154,6 +154,33 @@ Program::ExecuteAndWait(const Path& path,
*p = 0;
+ // The pointer to the environment block for the new process.
+ char *envblock = 0;
+
+ if (envp) {
+ // An environment block consists of a null-terminated block of
+ // null-terminated strings. Convert the array of environment variables to
+ // an environment block by concatenating them.
+
+ // First, determine the length of the environment block.
+ len = 0;
+ for (unsigned i = 0; envp[i]; i++)
+ len += strlen(envp[i]) + 1;
+
+ // Now build the environment block.
+ envblock = reinterpret_cast<char *>(_alloca(len+1));
+ p = envblock;
+
+ for (unsigned i = 0; envp[i]; i++) {
+ const char *ev = envp[i];
+ size_t len = strlen(ev) + 1;
+ memcpy(p, ev, len);
+ p += len;
+ }
+
+ *p = 0;
+ }
+
// Create a child process.
STARTUPINFO si;
memset(&si, 0, sizeof(si));
@@ -200,7 +227,7 @@ Program::ExecuteAndWait(const Path& path,
fflush(stdout);
fflush(stderr);
BOOL rc = CreateProcess(path.c_str(), command, NULL, NULL, FALSE, 0,
- envp, NULL, &si, &pi);
+ envblock, NULL, &si, &pi);
DWORD err = GetLastError();
// Regardless of whether the process got created or not, we are done with