1
1
//! Safe wrappers around posix_spawn* functions found in the libc "spawn.h" header.
2
2
3
- use std:: { ffi:: CStr , mem, os:: fd:: RawFd } ;
4
-
5
3
#[ cfg( any( feature = "fs" , feature = "term" ) ) ]
6
4
use crate :: fcntl:: OFlag ;
7
5
#[ cfg( feature = "signal" ) ]
8
6
use crate :: sys:: signal:: SigSet ;
9
7
#[ cfg( feature = "fs" ) ]
10
8
use crate :: sys:: stat:: Mode ;
11
9
use crate :: { errno:: Errno , unistd:: Pid , NixPath , Result } ;
10
+ use std:: os:: fd:: AsRawFd ;
11
+ use std:: { ffi:: CStr , mem} ;
12
12
13
13
/// A spawn attributes object. See [posix_spawnattr_t](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawnattr_init.html).
14
14
#[ repr( transparent) ]
@@ -277,7 +277,14 @@ impl PosixSpawnFileActions {
277
277
/// Add a [dup2](https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html) action. See
278
278
/// [posix_spawn_file_actions_adddup2](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn_file_actions_adddup2.html).
279
279
#[ doc( alias( "posix_spawn_file_actions_adddup2" ) ) ]
280
- pub fn add_dup2 ( & mut self , fd : RawFd , newfd : RawFd ) -> Result < ( ) > {
280
+ pub fn add_dup2 < Fd , NewFd > ( & mut self , fd : Fd , newfd : NewFd ) -> Result < ( ) >
281
+ where
282
+ Fd : std:: os:: fd:: AsFd ,
283
+ NewFd : std:: os:: fd:: AsFd ,
284
+ {
285
+ let fd = fd. as_fd ( ) . as_raw_fd ( ) ;
286
+ let newfd = newfd. as_fd ( ) . as_raw_fd ( ) ;
287
+
281
288
let res = unsafe {
282
289
libc:: posix_spawn_file_actions_adddup2 (
283
290
& mut self . fa as * mut libc:: posix_spawn_file_actions_t ,
@@ -295,13 +302,14 @@ impl PosixSpawnFileActions {
295
302
/// Add an open action. See
296
303
/// [posix_spawn_file_actions_addopen](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn_file_actions_addopen.html).
297
304
#[ doc( alias( "posix_spawn_file_actions_addopen" ) ) ]
298
- pub fn add_open<P : ?Sized + NixPath >(
305
+ pub fn add_open<Fd : std :: os :: fd :: AsFd , P : ?Sized + NixPath >(
299
306
& mut self ,
300
- fd: RawFd ,
307
+ fd: Fd ,
301
308
path: & P ,
302
309
oflag: OFlag ,
303
310
mode: Mode ,
304
311
) -> Result <( ) > {
312
+ let fd = fd. as_fd( ) . as_raw_fd( ) ;
305
313
let res = path. with_nix_path( |cstr| unsafe {
306
314
libc:: posix_spawn_file_actions_addopen(
307
315
& mut self . fa as * mut libc:: posix_spawn_file_actions_t,
@@ -320,7 +328,9 @@ impl PosixSpawnFileActions {
320
328
/// Add a close action. See
321
329
/// [posix_spawn_file_actions_addclose](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn_file_actions_addclose.html).
322
330
#[ doc( alias( "posix_spawn_file_actions_addclose" ) ) ]
323
- pub fn add_close ( & mut self , fd : RawFd ) -> Result < ( ) > {
331
+ pub fn add_close < Fd : std:: os:: fd:: AsFd > ( & mut self , fd : Fd ) -> Result < ( ) > {
332
+ let fd = fd. as_fd ( ) . as_raw_fd ( ) ;
333
+
324
334
let res = unsafe {
325
335
libc:: posix_spawn_file_actions_addclose (
326
336
& mut self . fa as * mut libc:: posix_spawn_file_actions_t ,
0 commit comments