@@ -589,6 +589,7 @@ fn make_command_line(prog: &CString, args: &[CString]) -> String {
589
589
}
590
590
}
591
591
592
+ #[ cfg( stage0) ]
592
593
fn with_envp < K , V , T , F > ( env : Option < & collections:: HashMap < K , V > > , cb : F ) -> T
593
594
where K : BytesContainer + Eq + Hash < Hasher > ,
594
595
V : BytesContainer ,
@@ -616,6 +617,34 @@ fn with_envp<K, V, T, F>(env: Option<&collections::HashMap<K, V>>, cb: F) -> T
616
617
_ => cb ( ptr:: null_mut ( ) )
617
618
}
618
619
}
620
+ #[ cfg( not( stage0) ) ]
621
+ fn with_envp < K , V , T , F > ( env : Option < & collections:: HashMap < K , V > > , cb : F ) -> T
622
+ where K : BytesContainer + Eq + Hash ,
623
+ V : BytesContainer ,
624
+ F : FnOnce ( * mut c_void ) -> T ,
625
+ {
626
+ // On Windows we pass an "environment block" which is not a char**, but
627
+ // rather a concatenation of null-terminated k=v\0 sequences, with a final
628
+ // \0 to terminate.
629
+ match env {
630
+ Some ( env) => {
631
+ let mut blk = Vec :: new ( ) ;
632
+
633
+ for pair in env {
634
+ let kv = format ! ( "{}={}" ,
635
+ pair. 0 . container_as_str( ) . unwrap( ) ,
636
+ pair. 1 . container_as_str( ) . unwrap( ) ) ;
637
+ blk. extend ( kv. utf16_units ( ) ) ;
638
+ blk. push ( 0 ) ;
639
+ }
640
+
641
+ blk. push ( 0 ) ;
642
+
643
+ cb ( blk. as_mut_ptr ( ) as * mut c_void )
644
+ }
645
+ _ => cb ( ptr:: null_mut ( ) )
646
+ }
647
+ }
619
648
620
649
fn with_dirp < T , F > ( d : Option < & CString > , cb : F ) -> T where
621
650
F : FnOnce ( * const u16 ) -> T ,
0 commit comments