@@ -7,32 +7,33 @@ use napi_derive::napi;
77
88#[ napi]
99pub fn execvp ( file : String , args : Vec < String > ) -> Result < ( ) > {
10- let file_cstring = CString :: new ( file. clone ( ) ) . unwrap ( ) ;
10+ let file_cstring = CString :: new ( file. clone ( ) ) . unwrap ( ) ;
1111
12- let args: Vec < CString > = args
13- . iter ( )
14- . map ( |arg| string_ref_to_c_str ( arg) . unwrap ( ) )
15- . collect ( ) ;
16- let args: Vec < & CStr > = args. iter ( ) . map ( |arg| arg. as_c_str ( ) ) . collect ( ) ;
12+ let args: Vec < CString > = args
13+ . iter ( )
14+ . map ( |arg| string_ref_to_c_str ( arg) . unwrap ( ) )
15+ . collect ( ) ;
16+ let args: Vec < & CStr > = args. iter ( ) . map ( |arg| arg. as_c_str ( ) ) . collect ( ) ;
1717
18- nix:: unistd:: execvp ( file_cstring. as_c_str ( ) , & args)
19- . map ( |_| ( ) )
20- . map_err ( |_| Error :: new ( Status :: GenericFailure , "execvp failed" ) )
18+ nix:: unistd:: execvp ( file_cstring. as_c_str ( ) , & args)
19+ . map ( |_| ( ) )
20+ . map_err ( |_| Error :: new ( Status :: GenericFailure , "execvp failed" ) )
2121}
2222
2323#[ napi]
2424pub fn do_not_close_on_exit ( fd : i32 ) -> Result < ( ) > {
25- let flags = nix:: fcntl:: fcntl ( fd, nix:: fcntl:: FcntlArg :: F_GETFD )
26- . map_err ( |_| Error :: new ( Status :: GenericFailure , "fcntl failed" ) ) ?;
25+ let flags = nix:: fcntl:: fcntl ( fd, nix:: fcntl:: FcntlArg :: F_GETFD )
26+ . map_err ( |_| Error :: new ( Status :: GenericFailure , "fcntl failed" ) ) ?;
2727
28- let flags_without_close_on_exec = flags & !nix:: fcntl:: FdFlag :: FD_CLOEXEC . bits ( ) ;
28+ let flags_without_close_on_exec = flags & !nix:: fcntl:: FdFlag :: FD_CLOEXEC . bits ( ) ;
2929
30- let new_flags = nix:: fcntl:: FdFlag :: from_bits_truncate ( flags_without_close_on_exec) ;
31- nix:: fcntl:: fcntl ( fd, nix:: fcntl:: FcntlArg :: F_SETFD ( new_flags) )
32- . map ( |_| ( ) )
33- . map_err ( |_| Error :: new ( Status :: GenericFailure , "fcntl failed" ) )
30+ let new_flags = nix:: fcntl:: FdFlag :: from_bits_truncate ( flags_without_close_on_exec) ;
31+ nix:: fcntl:: fcntl ( fd, nix:: fcntl:: FcntlArg :: F_SETFD ( new_flags) )
32+ . map ( |_| ( ) )
33+ . map_err ( |_| Error :: new ( Status :: GenericFailure , "fcntl failed" ) )
3434}
3535
3636fn string_ref_to_c_str ( string : & str ) -> Result < CString > {
37- CString :: new ( string. to_owned ( ) ) . map_err ( |_| Error :: new ( Status :: GenericFailure , "Invalid string" ) )
37+ CString :: new ( string. to_owned ( ) )
38+ . map_err ( |_| Error :: new ( Status :: GenericFailure , "Invalid string" ) )
3839}
0 commit comments