@@ -589,6 +589,7 @@ fn make_command_line(prog: &CString, args: &[CString]) -> String {
589589 }
590590}
591591
592+ #[ cfg( stage0) ]
592593fn with_envp < K , V , T , F > ( env : Option < & collections:: HashMap < K , V > > , cb : F ) -> T
593594 where K : BytesContainer + Eq + Hash < Hasher > ,
594595 V : BytesContainer ,
@@ -616,6 +617,34 @@ fn with_envp<K, V, T, F>(env: Option<&collections::HashMap<K, V>>, cb: F) -> T
616617 _ => cb ( ptr:: null_mut ( ) )
617618 }
618619}
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+ }
619648
620649fn with_dirp < T , F > ( d : Option < & CString > , cb : F ) -> T where
621650 F : FnOnce ( * const u16 ) -> T ,
0 commit comments