@@ -12,9 +12,9 @@ use libc::{self, c_char, c_void, c_int, c_long, c_uint, size_t, pid_t, off_t,
12
12
uid_t, gid_t, mode_t, PATH_MAX } ;
13
13
use std:: { fmt, mem, ptr} ;
14
14
use std:: convert:: Infallible ;
15
- use std:: ffi:: { CStr , OsString } ;
15
+ use std:: ffi:: { CStr , CString , OsString } ;
16
16
#[ cfg( not( target_os = "redox" ) ) ]
17
- use std:: ffi:: { CString , OsStr } ;
17
+ use std:: ffi:: { OsStr } ;
18
18
use std:: os:: unix:: ffi:: OsStringExt ;
19
19
#[ cfg( not( target_os = "redox" ) ) ]
20
20
use std:: os:: unix:: ffi:: OsStrExt ;
@@ -715,9 +715,9 @@ pub fn fchownat<P: ?Sized + NixPath>(
715
715
Errno :: result ( res) . map ( drop)
716
716
}
717
717
718
- fn to_exec_array ( args : & [ & CStr ] ) -> Vec < * const c_char > {
718
+ fn to_exec_array < S : AsRef < CStr > > ( args : & [ S ] ) -> Vec < * const c_char > {
719
719
use std:: iter:: once;
720
- args. iter ( ) . map ( |s| s. as_ptr ( ) ) . chain ( once ( ptr:: null ( ) ) ) . collect ( )
720
+ args. iter ( ) . map ( |s| s. as_ref ( ) . as_ptr ( ) ) . chain ( once ( ptr:: null ( ) ) ) . collect ( )
721
721
}
722
722
723
723
/// Replace the current process image with a new one (see
@@ -727,7 +727,7 @@ fn to_exec_array(args: &[&CStr]) -> Vec<*const c_char> {
727
727
/// performs the same action but does not allow for customization of the
728
728
/// environment for the new process.
729
729
#[ inline]
730
- pub fn execv ( path : & CStr , argv : & [ & CStr ] ) -> Result < Infallible > {
730
+ pub fn execv < S : AsRef < CStr > > ( path : & CStr , argv : & [ S ] ) -> Result < Infallible > {
731
731
let args_p = to_exec_array ( argv) ;
732
732
733
733
unsafe {
@@ -751,7 +751,7 @@ pub fn execv(path: &CStr, argv: &[&CStr]) -> Result<Infallible> {
751
751
/// in the `args` list is an argument to the new process. Each element in the
752
752
/// `env` list should be a string in the form "key=value".
753
753
#[ inline]
754
- pub fn execve ( path : & CStr , args : & [ & CStr ] , env : & [ & CStr ] ) -> Result < Infallible > {
754
+ pub fn execve < SA : AsRef < CStr > , SE : AsRef < CStr > > ( path : & CStr , args : & [ SA ] , env : & [ SE ] ) -> Result < Infallible > {
755
755
let args_p = to_exec_array ( args) ;
756
756
let env_p = to_exec_array ( env) ;
757
757
@@ -772,7 +772,7 @@ pub fn execve(path: &CStr, args: &[&CStr], env: &[&CStr]) -> Result<Infallible>
772
772
/// would not work if "bash" was specified for the path argument, but `execvp`
773
773
/// would assuming that a bash executable was on the system `PATH`.
774
774
#[ inline]
775
- pub fn execvp ( filename : & CStr , args : & [ & CStr ] ) -> Result < Infallible > {
775
+ pub fn execvp < S : AsRef < CStr > > ( filename : & CStr , args : & [ S ] ) -> Result < Infallible > {
776
776
let args_p = to_exec_array ( args) ;
777
777
778
778
unsafe {
@@ -792,7 +792,7 @@ pub fn execvp(filename: &CStr, args: &[&CStr]) -> Result<Infallible> {
792
792
#[ cfg( any( target_os = "haiku" ,
793
793
target_os = "linux" ,
794
794
target_os = "openbsd" ) ) ]
795
- pub fn execvpe ( filename : & CStr , args : & [ & CStr ] , env : & [ & CStr ] ) -> Result < Infallible > {
795
+ pub fn execvpe < SA : AsRef < CStr > , SE : AsRef < CStr > > ( filename : & CStr , args : & [ SA ] , env : & [ SE ] ) -> Result < Infallible > {
796
796
let args_p = to_exec_array ( args) ;
797
797
let env_p = to_exec_array ( env) ;
798
798
@@ -820,7 +820,7 @@ pub fn execvpe(filename: &CStr, args: &[&CStr], env: &[&CStr]) -> Result<Infalli
820
820
target_os = "linux" ,
821
821
target_os = "freebsd" ) ) ]
822
822
#[ inline]
823
- pub fn fexecve ( fd : RawFd , args : & [ & CStr ] , env : & [ & CStr ] ) -> Result < Infallible > {
823
+ pub fn fexecve < SA : AsRef < CStr > , SE : AsRef < CStr > > ( fd : RawFd , args : & [ SA ] , env : & [ SE ] ) -> Result < Infallible > {
824
824
let args_p = to_exec_array ( args) ;
825
825
let env_p = to_exec_array ( env) ;
826
826
@@ -843,8 +843,8 @@ pub fn fexecve(fd: RawFd, args: &[&CStr], env: &[&CStr]) -> Result<Infallible> {
843
843
/// is referenced as a file descriptor to the base directory plus a path.
844
844
#[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
845
845
#[ inline]
846
- pub fn execveat ( dirfd : RawFd , pathname : & CStr , args : & [ & CStr ] ,
847
- env : & [ & CStr ] , flags : super :: fcntl:: AtFlags ) -> Result < Infallible > {
846
+ pub fn execveat < SA : AsRef < CStr > , SE : AsRef < CStr > > ( dirfd : RawFd , pathname : & CStr , args : & [ SA ] ,
847
+ env : & [ SE ] , flags : super :: fcntl:: AtFlags ) -> Result < Infallible > {
848
848
let args_p = to_exec_array ( args) ;
849
849
let env_p = to_exec_array ( env) ;
850
850
0 commit comments