about summary refs log tree commit diff
path: root/src/libstd/sys/windows/process.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-02-18 18:02:58 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-02-19 07:03:18 -0800
commit0cd54b85ef1fdad3bc4c1c4e1a989b9f6540a0fa (patch)
treeb2973ab6fdb99ec1d3ff8fd930f29cf78da183f4 /src/libstd/sys/windows/process.rs
parentcb29c468f38ba93f624277c2c3a8e46a4d85e619 (diff)
downloadrust-0cd54b85ef1fdad3bc4c1c4e1a989b9f6540a0fa.tar.gz
rust-0cd54b85ef1fdad3bc4c1c4e1a989b9f6540a0fa.zip
Round 5 test fixes and rebase conflicts
Diffstat (limited to 'src/libstd/sys/windows/process.rs')
-rw-r--r--src/libstd/sys/windows/process.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs
index e001cd9a1ec..60d24e6174f 100644
--- a/src/libstd/sys/windows/process.rs
+++ b/src/libstd/sys/windows/process.rs
@@ -589,6 +589,7 @@ fn make_command_line(prog: &CString, args: &[CString]) -> String {
     }
 }
 
+#[cfg(stage0)]
 fn with_envp<K, V, T, F>(env: Option<&collections::HashMap<K, V>>, cb: F) -> T
     where K: BytesContainer + Eq + Hash<Hasher>,
           V: BytesContainer,
@@ -616,6 +617,34 @@ fn with_envp<K, V, T, F>(env: Option<&collections::HashMap<K, V>>, cb: F) -> T
         _ => cb(ptr::null_mut())
     }
 }
+#[cfg(not(stage0))]
+fn with_envp<K, V, T, F>(env: Option<&collections::HashMap<K, V>>, cb: F) -> T
+    where K: BytesContainer + Eq + Hash,
+          V: BytesContainer,
+          F: FnOnce(*mut c_void) -> T,
+{
+    // On Windows we pass an "environment block" which is not a char**, but
+    // rather a concatenation of null-terminated k=v\0 sequences, with a final
+    // \0 to terminate.
+    match env {
+        Some(env) => {
+            let mut blk = Vec::new();
+
+            for pair in env {
+                let kv = format!("{}={}",
+                                 pair.0.container_as_str().unwrap(),
+                                 pair.1.container_as_str().unwrap());
+                blk.extend(kv.utf16_units());
+                blk.push(0);
+            }
+
+            blk.push(0);
+
+            cb(blk.as_mut_ptr() as *mut c_void)
+        }
+        _ => cb(ptr::null_mut())
+    }
+}
 
 fn with_dirp<T, F>(d: Option<&CString>, cb: F) -> T where
     F: FnOnce(*const u16) -> T,