Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: apply the netbsdlike alias for src/* #2231

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ cfg_if! {
unsafe fn errno_location() -> *mut c_int {
unsafe { libc::__error() }
}
} else if #[cfg(any(target_os = "android",
target_os = "netbsd",
target_os = "openbsd"))] {
} else if #[cfg(any(target_os = "android", netbsdlike))] {
unsafe fn errno_location() -> *mut c_int {
unsafe { libc::__errno() }
}
Expand Down
7 changes: 2 additions & 5 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ libc_bitflags!(
#[cfg(not(solarish))]
O_DIRECTORY;
/// Implicitly follow each `write()` with an `fdatasync()`.
#[cfg(any(linux_android,
apple_targets,
target_os = "netbsd",
target_os = "openbsd"))]
#[cfg(any(linux_android, apple_targets, netbsdlike))]
O_DSYNC;
/// Error out if a file was not created.
O_EXCL;
Expand Down Expand Up @@ -150,7 +147,7 @@ libc_bitflags!(
/// This should not be combined with `O_WRONLY` or `O_RDONLY`.
O_RDWR;
/// Similar to `O_DSYNC` but applies to `read`s instead.
#[cfg(any(target_os = "linux", target_os = "netbsd", target_os = "openbsd"))]
#[cfg(any(target_os = "linux", netbsdlike))]
O_RSYNC;
/// Skip search permission checks.
#[cfg(target_os = "netbsd")]
Expand Down
3 changes: 1 addition & 2 deletions src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ mod os {

#[cfg(any(
freebsdlike, // FreeBSD since 10.0 DragonFlyBSD since ???
netbsdlike, // NetBSD since 6.0 OpenBSD since 5.7
target_os = "illumos", // Since ???
target_os = "netbsd", // Since 6.0
target_os = "openbsd", // Since 5.7
target_os = "redox", // Since 1-july-2020
))]
mod os {
Expand Down
6 changes: 1 addition & 5 deletions src/mount/bsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ libc_bitflags!(
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
MNT_SNAPSHOT;
/// Using soft updates.
#[cfg(any(
freebsdlike,
target_os = "netbsd",
target_os = "openbsd"
))]
#[cfg(any(freebsdlike, netbsdlike))]
MNT_SOFTDEP;
/// Directories with the SUID bit set chown new files to their own
/// owner.
Expand Down
14 changes: 2 additions & 12 deletions src/mount/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,8 @@ mod linux;
#[cfg(linux_android)]
pub use self::linux::*;

#[cfg(any(
freebsdlike,
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
))]
#[cfg(any(freebsdlike, netbsdlike, target_os = "macos"))]
mod bsd;

#[cfg(any(
freebsdlike,
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
))]
#[cfg(any(freebsdlike, netbsdlike, target_os = "macos"))]
pub use self::bsd::*;
10 changes: 2 additions & 8 deletions src/net/if_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ libc_bitflags!(
#[cfg(any(linux_android, target_os = "fuchsia"))]
IFF_MASTER;
/// transmission in progress, tx hardware queue is full
#[cfg(any(target_os = "freebsd",
apple_targets,
target_os = "netbsd",
target_os = "openbsd"))]
#[cfg(any(target_os = "freebsd", apple_targets, netbsdlike))]
IFF_OACTIVE;
/// Protocol code on board.
#[cfg(solarish)]
Expand All @@ -85,10 +82,7 @@ libc_bitflags!(
#[cfg(any(linux_android, target_os = "fuchsia"))]
IFF_SLAVE;
/// Can't hear own transmissions.
#[cfg(any(freebsdlike,
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
#[cfg(any(freebsdlike, netbsdlike, target_os = "macos"))]
IFF_SIMPLEX;
/// Supports multicast. (see
/// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html))
Expand Down
3 changes: 1 addition & 2 deletions src/sys/aio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ libc_enum! {
/// on supported operating systems only, do it like `fdatasync`
#[cfg(any(apple_targets,
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd"))]
netbsdlike))]
O_DSYNC
}
impl TryFrom<i32>
Expand Down
4 changes: 2 additions & 2 deletions src/sys/mman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ libc_bitflags! {
/// Rename private pages to a file.
///
/// This was removed in FreeBSD 11 and is unused in DragonFlyBSD.
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
#[cfg(netbsdlike)]
MAP_RENAME;
/// Region may contain semaphores.
#[cfg(any(freebsdlike, target_os = "netbsd", target_os = "openbsd"))]
#[cfg(any(freebsdlike, netbsdlike))]
MAP_HASSEMAPHORE;
/// Region grows down, like a stack.
#[cfg(any(linux_android, freebsdlike, target_os = "openbsd"))]
Expand Down
8 changes: 1 addition & 7 deletions src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,7 @@ feature! {
pub mod pthread;
}

#[cfg(any(
linux_android,
freebsdlike,
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
))]
#[cfg(any(linux_android, freebsdlike, target_os = "macos", netbsdlike))]
feature! {
#![feature = "ptrace"]
#[allow(missing_docs)]
Expand Down
14 changes: 2 additions & 12 deletions src/sys/ptrace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,8 @@ mod linux;
#[cfg(linux_android)]
pub use self::linux::*;

#[cfg(any(
freebsdlike,
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
))]
#[cfg(any(freebsdlike, netbsdlike, target_os = "macos"))]
mod bsd;

#[cfg(any(
freebsdlike,
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
))]
#[cfg(any(freebsdlike, netbsdlike, target_os = "macos"))]
pub use self::bsd::*;
15 changes: 4 additions & 11 deletions src/sys/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ libc_enum! {
), repr(i32))]
#[non_exhaustive]
pub enum Resource {
#[cfg(not(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")))]
#[cfg(not(any(target_os = "freebsd", netbsdlike)))]
/// The maximum amount (in bytes) of virtual memory the process is
/// allowed to map.
RLIMIT_AS,
Expand All @@ -74,12 +74,7 @@ libc_enum! {
/// this process may establish.
RLIMIT_LOCKS,

#[cfg(any(
linux_android,
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd"
))]
#[cfg(any(linux_android, target_os = "freebsd", netbsdlike))]
/// The maximum size (in bytes) which a process may lock into memory
/// using the mlock(2) system call.
RLIMIT_MEMLOCK,
Expand All @@ -97,8 +92,7 @@ libc_enum! {
#[cfg(any(
linux_android,
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
netbsdlike,
target_os = "aix",
))]
/// The maximum number of simultaneous processes for this user id.
Expand All @@ -111,8 +105,7 @@ libc_enum! {

#[cfg(any(linux_android,
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
netbsdlike,
target_os = "aix",
))]
/// When there is memory pressure and swap is available, prioritize
Expand Down
2 changes: 1 addition & 1 deletion src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub enum AddressFamily {
#[cfg(bsd)]
Chaos = libc::AF_CHAOS,
/// Novell and Xerox protocol
#[cfg(any(apple_targets, target_os = "netbsd", target_os = "openbsd"))]
#[cfg(any(apple_targets, netbsdlike))]
Ns = libc::AF_NS,
#[allow(missing_docs)] // Not documented anywhere that I can find
#[cfg(bsd)]
Expand Down
69 changes: 19 additions & 50 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,14 @@ libc_bitflags! {
/// Set non-blocking mode on the new socket
#[cfg(any(linux_android,
freebsdlike,
target_os = "illumos",
target_os = "netbsd",
target_os = "openbsd"))]
netbsdlike,
target_os = "illumos"))]
SOCK_NONBLOCK;
/// Set close-on-exec on the new descriptor
#[cfg(any(linux_android,
freebsdlike,
target_os = "illumos",
target_os = "netbsd",
target_os = "openbsd"))]
netbsdlike,
target_os = "illumos"))]
SOCK_CLOEXEC;
/// Return `EPIPE` instead of raising `SIGPIPE`
#[cfg(target_os = "netbsd")]
Expand Down Expand Up @@ -329,28 +327,23 @@ libc_bitflags! {
/// [open(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html).
///
/// Only used in [`recvmsg`](fn.recvmsg.html) function.
#[cfg(any(linux_android,
freebsdlike,
target_os = "netbsd",
target_os = "openbsd"))]
#[cfg(any(linux_android, freebsdlike, netbsdlike))]
MSG_CMSG_CLOEXEC;
/// Requests not to send `SIGPIPE` errors when the other end breaks the connection.
/// (For more details, see [send(2)](https://linux.die.net/man/2/send)).
#[cfg(any(linux_android,
freebsdlike,
solarish,
netbsdlike,
target_os = "fuchsia",
target_os = "haiku",
target_os = "netbsd",
target_os = "openbsd"))]
target_os = "haiku"))]
MSG_NOSIGNAL;
/// Turns on [`MSG_DONTWAIT`] after the first message has been received (only for
/// `recvmmsg()`).
#[cfg(any(linux_android,
netbsdlike,
target_os = "fuchsia",
target_os = "netbsd",
target_os = "freebsd",
target_os = "openbsd",
target_os = "solaris"))]
MSG_WAITFORONE;
}
Expand Down Expand Up @@ -755,21 +748,11 @@ pub enum ControlMessageOwned {
#[cfg(feature = "net")]
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Ipv6PacketInfo(libc::in6_pktinfo),
#[cfg(any(
target_os = "freebsd",
apple_targets,
target_os = "netbsd",
target_os = "openbsd",
))]
#[cfg(any(target_os = "freebsd", apple_targets, netbsdlike))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A quick search of libc shows that dragonfly supports this, so it could be marked #[cfg(bsd)]. But that's not the purpose of this PR. Same for Ipv4RecvDstAddr.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will handle them in a separate PR.

#[cfg(feature = "net")]
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Ipv4RecvIf(libc::sockaddr_dl),
#[cfg(any(
target_os = "freebsd",
apple_targets,
target_os = "netbsd",
target_os = "openbsd",
))]
#[cfg(any(target_os = "freebsd", apple_targets, netbsdlike))]
#[cfg(feature = "net")]
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Ipv4RecvDstAddr(libc::in_addr),
Expand Down Expand Up @@ -948,23 +931,13 @@ impl ControlMessageOwned {
let info = unsafe { ptr::read_unaligned(p as *const libc::in_pktinfo) };
ControlMessageOwned::Ipv4PacketInfo(info)
}
#[cfg(any(
target_os = "freebsd",
apple_targets,
target_os = "netbsd",
target_os = "openbsd",
))]
#[cfg(any(target_os = "freebsd", apple_targets, netbsdlike))]
#[cfg(feature = "net")]
(libc::IPPROTO_IP, libc::IP_RECVIF) => {
let dl = unsafe { ptr::read_unaligned(p as *const libc::sockaddr_dl) };
ControlMessageOwned::Ipv4RecvIf(dl)
},
#[cfg(any(
target_os = "freebsd",
apple_targets,
target_os = "netbsd",
target_os = "openbsd",
))]
#[cfg(any(target_os = "freebsd", apple_targets, netbsdlike))]
#[cfg(feature = "net")]
(libc::IPPROTO_IP, libc::IP_RECVDSTADDR) => {
let dl = unsafe { ptr::read_unaligned(p as *const libc::in_addr) };
Expand Down Expand Up @@ -1124,10 +1097,7 @@ pub enum ControlMessage<'a> {
///
/// For further information, please refer to the
/// [`ip(7)`](https://man7.org/linux/man-pages/man7/ip.7.html) man page.
#[cfg(any(target_os = "linux",
target_os = "netbsd",
target_os = "android",
apple_targets))]
#[cfg(any(linux_android, target_os = "netbsd", apple_targets))]
#[cfg(feature = "net")]
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Ipv4PacketInfo(&'a libc::in_pktinfo),
Expand All @@ -1145,7 +1115,7 @@ pub enum ControlMessage<'a> {
Ipv6PacketInfo(&'a libc::in6_pktinfo),

/// Configure the IPv4 source address with `IP_SENDSRCADDR`.
#[cfg(any(freebsdlike, target_os = "netbsd", target_os = "openbsd"))]
#[cfg(any(freebsdlike, netbsdlike))]
#[cfg(feature = "net")]
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Ipv4SendSrcAddr(&'a libc::in_addr),
Expand Down Expand Up @@ -1268,7 +1238,7 @@ impl<'a> ControlMessage<'a> {
target_os = "freebsd", apple_targets))]
#[cfg(feature = "net")]
ControlMessage::Ipv6PacketInfo(info) => info as *const _ as *const u8,
#[cfg(any(freebsdlike, target_os = "netbsd", target_os = "openbsd"))]
#[cfg(any(freebsdlike, netbsdlike))]
#[cfg(feature = "net")]
ControlMessage::Ipv4SendSrcAddr(addr) => addr as *const _ as *const u8,
#[cfg(any(linux_android, freebsdlike, apple_targets, target_os = "haiku"))]
Expand Down Expand Up @@ -1330,7 +1300,7 @@ impl<'a> ControlMessage<'a> {
target_os = "freebsd", apple_targets))]
#[cfg(feature = "net")]
ControlMessage::Ipv6PacketInfo(info) => mem::size_of_val(info),
#[cfg(any(freebsdlike, target_os = "netbsd", target_os = "openbsd"))]
#[cfg(any(freebsdlike, netbsdlike))]
#[cfg(feature = "net")]
ControlMessage::Ipv4SendSrcAddr(addr) => mem::size_of_val(addr),
#[cfg(any(linux_android, freebsdlike, apple_targets, target_os = "haiku"))]
Expand Down Expand Up @@ -1370,7 +1340,7 @@ impl<'a> ControlMessage<'a> {
target_os = "freebsd", apple_targets))]
#[cfg(feature = "net")]
ControlMessage::Ipv6PacketInfo(_) => libc::IPPROTO_IPV6,
#[cfg(any(freebsdlike, target_os = "netbsd", target_os = "openbsd"))]
#[cfg(any(freebsdlike, netbsdlike))]
#[cfg(feature = "net")]
ControlMessage::Ipv4SendSrcAddr(_) => libc::IPPROTO_IP,
#[cfg(any(linux_android, freebsdlike, apple_targets, target_os = "haiku"))]
Expand Down Expand Up @@ -1415,7 +1385,7 @@ impl<'a> ControlMessage<'a> {
target_os = "freebsd", apple_targets))]
#[cfg(feature = "net")]
ControlMessage::Ipv6PacketInfo(_) => libc::IPV6_PKTINFO,
#[cfg(any(freebsdlike, target_os = "netbsd", target_os = "openbsd"))]
#[cfg(any(freebsdlike, netbsdlike))]
#[cfg(feature = "net")]
ControlMessage::Ipv4SendSrcAddr(_) => libc::IP_SENDSRCADDR,
#[cfg(any(linux_android, freebsdlike, apple_targets, target_os = "haiku"))]
Expand Down Expand Up @@ -2183,12 +2153,11 @@ pub fn accept(sockfd: RawFd) -> Result<RawFd> {
)
),
freebsdlike,
netbsdlike,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "illumos",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd"
))]
pub fn accept4(sockfd: RawFd, flags: SockFlag) -> Result<RawFd> {
let res = unsafe {
Expand Down
Loading