11use crate :: os:: unix:: prelude:: * ;
22
3- use crate :: ffi:: { OsString , OsStr , CString } ;
3+ use crate :: ffi:: { OsString , OsStr , CString , CStr } ;
44use crate :: fmt;
55use crate :: io;
66use crate :: ptr;
@@ -11,10 +11,7 @@ use crate::sys_common::process::CommandEnv;
1111use crate :: collections:: BTreeMap ;
1212
1313#[ cfg( not( target_os = "fuchsia" ) ) ]
14- use {
15- crate :: ffi:: CStr ,
16- crate :: sys:: fs:: OpenOptions ,
17- } ;
14+ use crate :: sys:: fs:: OpenOptions ;
1815
1916use libc:: { c_int, gid_t, uid_t, c_char, EXIT_SUCCESS , EXIT_FAILURE } ;
2017
@@ -135,8 +132,8 @@ impl Command {
135132 let program = os2c ( program, & mut saw_nul) ;
136133 Command {
137134 argv : Argv ( vec ! [ program. as_ptr( ) , ptr:: null( ) ] ) ,
135+ args : vec ! [ program. clone( ) ] ,
138136 program,
139- args : Vec :: new ( ) ,
140137 env : Default :: default ( ) ,
141138 cwd : None ,
142139 uid : None ,
@@ -149,11 +146,19 @@ impl Command {
149146 }
150147 }
151148
149+ pub fn set_arg_0 ( & mut self , arg : & OsStr ) {
150+ // Set a new arg0
151+ let arg = os2c ( arg, & mut self . saw_nul ) ;
152+ debug_assert ! ( self . argv. 0 . len( ) > 1 ) ;
153+ self . argv . 0 [ 0 ] = arg. as_ptr ( ) ;
154+ self . args [ 0 ] = arg;
155+ }
156+
152157 pub fn arg ( & mut self , arg : & OsStr ) {
153158 // Overwrite the trailing NULL pointer in `argv` and then add a new null
154159 // pointer.
155160 let arg = os2c ( arg, & mut self . saw_nul ) ;
156- self . argv . 0 [ self . args . len ( ) + 1 ] = arg. as_ptr ( ) ;
161+ self . argv . 0 [ self . args . len ( ) ] = arg. as_ptr ( ) ;
157162 self . argv . 0 . push ( ptr:: null ( ) ) ;
158163
159164 // Also make sure we keep track of the owned value to schedule a
@@ -178,6 +183,10 @@ impl Command {
178183 & self . argv . 0
179184 }
180185
186+ pub fn get_program ( & self ) -> & CStr {
187+ & * self . program
188+ }
189+
181190 #[ allow( dead_code) ]
182191 pub fn get_cwd ( & self ) -> & Option < CString > {
183192 & self . cwd
0 commit comments