MCPcopy Index your code
hub / github.com/RustPython/RustPython / close_dir_fds

Function close_dir_fds

crates/stdlib/src/posixsubprocess.rs:435–470  ·  view source on GitHub ↗
(keep: KeepFds<'_>)

Source from the content-addressed store, hash-verified

433
434#[cfg(not(target_os = "redox"))]
435fn close_dir_fds(keep: KeepFds<'_>) -> nix::Result<()> {
436 use nix::{dir::Dir, fcntl::OFlag};
437
438 #[cfg(any(
439 target_os = "dragonfly",
440 target_os = "freebsd",
441 target_os = "netbsd",
442 target_os = "openbsd",
443 target_vendor = "apple",
444 ))]
445 let fd_dir_name = c"/dev/fd";
446
447 #[cfg(any(target_os = "linux", target_os = "android"))]
448 let fd_dir_name = c"/proc/self/fd";
449
450 let mut dir = Dir::open(
451 fd_dir_name,
452 OFlag::O_RDONLY | OFlag::O_DIRECTORY,
453 nix::sys::stat::Mode::empty(),
454 )?;
455 let dirfd = dir.as_raw_fd();
456 'outer: for e in dir.iter() {
457 let e = e?;
458 let mut parser = IntParser::default();
459 for &c in e.file_name().to_bytes() {
460 if parser.feed(c).is_err() {
461 continue 'outer;
462 }
463 }
464 let fd = parser.num;
465 if fd != dirfd && keep.should_keep(fd) {
466 let _ = unistd::close(fd);
467 }
468 }
469 Ok(())
470}
471
472#[cfg(target_os = "redox")]
473fn close_filetable_fds(keep: KeepFds<'_>) -> nix::Result<()> {

Callers 1

close_fdsFunction · 0.85

Calls 8

to_bytesMethod · 0.80
is_errMethod · 0.80
should_keepMethod · 0.80
closeFunction · 0.70
openFunction · 0.50
as_raw_fdMethod · 0.45
iterMethod · 0.45
feedMethod · 0.45

Tested by

no test coverage detected