1
1
use crate :: os:: unix:: prelude:: * ;
2
2
3
- use crate :: ffi:: { OsString , OsStr , CString } ;
3
+ use crate :: ffi:: { OsString , OsStr , CString , CStr } ;
4
4
use crate :: fmt;
5
5
use crate :: io;
6
6
use crate :: ptr;
@@ -11,10 +11,7 @@ use crate::sys_common::process::CommandEnv;
11
11
use crate :: collections:: BTreeMap ;
12
12
13
13
#[ cfg( not( target_os = "fuchsia" ) ) ]
14
- use {
15
- crate :: ffi:: CStr ,
16
- crate :: sys:: fs:: OpenOptions ,
17
- } ;
14
+ use crate :: sys:: fs:: OpenOptions ;
18
15
19
16
use libc:: { c_int, gid_t, uid_t, c_char, EXIT_SUCCESS , EXIT_FAILURE } ;
20
17
@@ -135,8 +132,8 @@ impl Command {
135
132
let program = os2c ( program, & mut saw_nul) ;
136
133
Command {
137
134
argv : Argv ( vec ! [ program. as_ptr( ) , ptr:: null( ) ] ) ,
135
+ args : vec ! [ program. clone( ) ] ,
138
136
program,
139
- args : Vec :: new ( ) ,
140
137
env : Default :: default ( ) ,
141
138
cwd : None ,
142
139
uid : None ,
@@ -149,11 +146,19 @@ impl Command {
149
146
}
150
147
}
151
148
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
+
152
157
pub fn arg ( & mut self , arg : & OsStr ) {
153
158
// Overwrite the trailing NULL pointer in `argv` and then add a new null
154
159
// pointer.
155
160
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 ( ) ;
157
162
self . argv . 0 . push ( ptr:: null ( ) ) ;
158
163
159
164
// Also make sure we keep track of the owned value to schedule a
@@ -178,6 +183,10 @@ impl Command {
178
183
& self . argv . 0
179
184
}
180
185
186
+ pub fn get_program ( & self ) -> & CStr {
187
+ & * self . program
188
+ }
189
+
181
190
#[ allow( dead_code) ]
182
191
pub fn get_cwd ( & self ) -> & Option < CString > {
183
192
& self . cwd
0 commit comments