Skip to content

Commit 98ce770

Browse files
authored
fix: build for freebsd (reubeno#980)
Also sets FD_DIR_PATH for other BSD distros.
1 parent d0d3433 commit 98ce770

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

  • brush-core/src/sys/unix

brush-core/src/sys/unix/fd.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,36 @@ use std::os::fd::RawFd;
44

55
use 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+
))]
1837
pub 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

Comments
 (0)