@@ -4,17 +4,36 @@ use std::os::fd::RawFd;
44
55use crate :: { ShellFd , error, openfiles} ;
66
7- #[ cfg( target_os = "linux" ) ]
8- const FD_DIR_PATH : & str = "/proc/self/fd" ;
9-
10- #[ cfg( target_os = "macos" ) ]
11- const FD_DIR_PATH : & str = "/dev/fd" ;
7+ cfg_if:: cfg_if! {
8+ if #[ cfg( target_os = "linux" ) ] {
9+ const FD_DIR_PATH : & str = "/proc/self/fd" ;
10+ } else if #[ cfg( any(
11+ target_os = "freebsd" ,
12+ target_os = "macos" ,
13+ target_os = "netbsd" ,
14+ target_os = "openbsd"
15+ ) ) ] {
16+ const FD_DIR_PATH : & str = "/dev/fd" ;
17+ } else {
18+ pub fn iter_fds( )
19+ -> Result <impl Iterator <Item = ( ShellFd , openfiles:: OpenFile ) >, error:: Error > {
20+ Ok ( std:: iter:: empty( ) )
21+ }
22+ }
23+ }
1224
1325/// Makes a best-effort attempt to iterate over all open file descriptors
1426/// for the current process.
1527///
1628/// If the platform does not support enumerating file descriptors, an empty iterator
1729/// is returned. This function will skip any file descriptors that cannot be opened.
30+ #[ cfg( any(
31+ target_os = "freebsd" ,
32+ target_os = "linux" ,
33+ target_os = "macos" ,
34+ target_os = "netbsd" ,
35+ target_os = "openbsd"
36+ ) ) ]
1837pub fn try_iter_open_fds ( ) -> impl Iterator < Item = ( ShellFd , openfiles:: OpenFile ) > {
1938 let mut opened_entries = vec ! [ ] ;
2039
@@ -40,11 +59,6 @@ pub fn try_iter_open_fds() -> impl Iterator<Item = (ShellFd, openfiles::OpenFile
4059 opened_entries. into_iter ( )
4160}
4261
43- #[ cfg( not( any( target_os = "linux" , target_os = "macos" ) ) ) ]
44- pub fn iter_fds ( ) -> Result < impl Iterator < Item = ( ShellFd , openfiles:: OpenFile ) > , error:: Error > {
45- Ok ( std:: iter:: empty ( ) )
46- }
47-
4862/// Attempts to retrieve an `OpenFile` representation for the given already-open file descriptor.
4963///
5064/// If the file descriptor cannot be opened, `None` is returned. Note that there is no guarantee
0 commit comments