@@ -7,7 +7,7 @@ use fcntl::FcntlArg::F_SETFD;
7
7
use libc:: { self , c_char, c_void, c_int, c_long, c_uint, size_t, pid_t, off_t,
8
8
uid_t, gid_t, mode_t} ;
9
9
use std:: { fmt, mem, ptr} ;
10
- use std:: ffi:: { CString , CStr , OsString , OsStr } ;
10
+ use std:: ffi:: { CStr , OsString , OsStr } ;
11
11
use std:: os:: unix:: ffi:: { OsStringExt , OsStrExt } ;
12
12
use std:: os:: unix:: io:: RawFd ;
13
13
use std:: path:: PathBuf ;
@@ -663,10 +663,9 @@ pub fn fchownat<P: ?Sized + NixPath>(
663
663
Errno :: result ( res) . map ( drop)
664
664
}
665
665
666
- fn to_exec_array ( args : & [ CString ] ) -> Vec < * const c_char > {
667
- let mut args_p: Vec < * const c_char > = args. iter ( ) . map ( |s| s. as_ptr ( ) ) . collect ( ) ;
668
- args_p. push ( ptr:: null ( ) ) ;
669
- args_p
666
+ fn to_exec_array ( args : & [ & CStr ] ) -> Vec < * const c_char > {
667
+ use std:: iter:: once;
668
+ args. iter ( ) . map ( |s| s. as_ptr ( ) ) . chain ( once ( ptr:: null ( ) ) ) . collect ( )
670
669
}
671
670
672
671
/// Replace the current process image with a new one (see
@@ -676,7 +675,7 @@ fn to_exec_array(args: &[CString]) -> Vec<*const c_char> {
676
675
/// performs the same action but does not allow for customization of the
677
676
/// environment for the new process.
678
677
#[ inline]
679
- pub fn execv ( path : & CString , argv : & [ CString ] ) -> Result < Void > {
678
+ pub fn execv ( path : & CStr , argv : & [ & CStr ] ) -> Result < Void > {
680
679
let args_p = to_exec_array ( argv) ;
681
680
682
681
unsafe {
@@ -700,7 +699,7 @@ pub fn execv(path: &CString, argv: &[CString]) -> Result<Void> {
700
699
/// in the `args` list is an argument to the new process. Each element in the
701
700
/// `env` list should be a string in the form "key=value".
702
701
#[ inline]
703
- pub fn execve ( path : & CString , args : & [ CString ] , env : & [ CString ] ) -> Result < Void > {
702
+ pub fn execve ( path : & CStr , args : & [ & CStr ] , env : & [ & CStr ] ) -> Result < Void > {
704
703
let args_p = to_exec_array ( args) ;
705
704
let env_p = to_exec_array ( env) ;
706
705
@@ -721,7 +720,7 @@ pub fn execve(path: &CString, args: &[CString], env: &[CString]) -> Result<Void>
721
720
/// would not work if "bash" was specified for the path argument, but `execvp`
722
721
/// would assuming that a bash executable was on the system `PATH`.
723
722
#[ inline]
724
- pub fn execvp ( filename : & CString , args : & [ CString ] ) -> Result < Void > {
723
+ pub fn execvp ( filename : & CStr , args : & [ & CStr ] ) -> Result < Void > {
725
724
let args_p = to_exec_array ( args) ;
726
725
727
726
unsafe {
@@ -741,7 +740,7 @@ pub fn execvp(filename: &CString, args: &[CString]) -> Result<Void> {
741
740
#[ cfg( any( target_os = "haiku" ,
742
741
target_os = "linux" ,
743
742
target_os = "openbsd" ) ) ]
744
- pub fn execvpe ( filename : & CString , args : & [ CString ] , env : & [ CString ] ) -> Result < Void > {
743
+ pub fn execvpe ( filename : & CStr , args : & [ & CStr ] , env : & [ & CStr ] ) -> Result < Void > {
745
744
let args_p = to_exec_array ( args) ;
746
745
let env_p = to_exec_array ( env) ;
747
746
@@ -769,7 +768,7 @@ pub fn execvpe(filename: &CString, args: &[CString], env: &[CString]) -> Result<
769
768
target_os = "linux" ,
770
769
target_os = "freebsd" ) ) ]
771
770
#[ inline]
772
- pub fn fexecve ( fd : RawFd , args : & [ CString ] , env : & [ CString ] ) -> Result < Void > {
771
+ pub fn fexecve ( fd : RawFd , args : & [ & CStr ] , env : & [ & CStr ] ) -> Result < Void > {
773
772
let args_p = to_exec_array ( args) ;
774
773
let env_p = to_exec_array ( env) ;
775
774
@@ -792,8 +791,8 @@ pub fn fexecve(fd: RawFd, args: &[CString], env: &[CString]) -> Result<Void> {
792
791
/// is referenced as a file descriptor to the base directory plus a path.
793
792
#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
794
793
#[ inline]
795
- pub fn execveat ( dirfd : RawFd , pathname : & CString , args : & [ CString ] ,
796
- env : & [ CString ] , flags : super :: fcntl:: AtFlags ) -> Result < Void > {
794
+ pub fn execveat ( dirfd : RawFd , pathname : & CStr , args : & [ & CStr ] ,
795
+ env : & [ & CStr ] , flags : super :: fcntl:: AtFlags ) -> Result < Void > {
797
796
let args_p = to_exec_array ( args) ;
798
797
let env_p = to_exec_array ( env) ;
799
798
0 commit comments