Skip to content

refactor: cfg for fcntl/fetures/ifaddrs/lib/poll/sched/time #2215

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

Merged
merged 2 commits into from
Nov 27, 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
63 changes: 25 additions & 38 deletions src/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ use std::os::unix::io::RawFd;
all(target_os = "freebsd", target_arch = "x86_64"),
))]
use std::path::PathBuf;
#[cfg(any(
target_os = "android",
target_os = "freebsd",
target_os = "linux"
))]
#[cfg(any(linux_android, target_os = "freebsd"))]
use std::{
os::unix::io::{AsFd, AsRawFd},
ptr,
Expand All @@ -36,8 +32,7 @@ use std::{
use crate::{sys::stat::Mode, NixPath, Result};

#[cfg(any(
target_os = "linux",
target_os = "android",
linux_android,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "wasi",
Expand Down Expand Up @@ -81,10 +76,11 @@ libc_bitflags!(
/// Open the file in append-only mode.
O_APPEND;
/// Generate a signal when input or output becomes possible.
#[cfg(not(any(target_os = "aix",
target_os = "illumos",
target_os = "solaris",
target_os = "haiku")))]
#[cfg(not(any(
solarish,
target_os = "aix",
target_os = "haiku"
)))]
O_ASYNC;
/// Closes the file descriptor once an `execve` call is made.
///
Expand All @@ -93,19 +89,18 @@ libc_bitflags!(
/// Create the file if it does not exist.
O_CREAT;
/// Try to minimize cache effects of the I/O for this file.
#[cfg(any(target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "linux",
target_os = "netbsd"))]
#[cfg(any(
freebsdlike,
linux_android,
target_os = "netbsd"
))]
O_DIRECT;
/// If the specified path isn't a directory, fail.
#[cfg(not(solarish))]
O_DIRECTORY;
/// Implicitly follow each `write()` with an `fdatasync()`.
#[cfg(any(target_os = "android",
#[cfg(any(linux_android,
apple_targets,
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd"))]
O_DSYNC;
Expand Down Expand Up @@ -144,7 +139,7 @@ libc_bitflags!(
/// Obtain a file descriptor for low-level access.
///
/// The file itself is not opened and other file operations will fail.
#[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))]
#[cfg(any(linux_android, target_os = "redox"))]
O_PATH;
/// Only allow reading.
///
Expand Down Expand Up @@ -184,7 +179,7 @@ libc_bitflags!(
/// Computes the raw fd consumed by a function of the form `*at`.
#[cfg(any(
all(feature = "fs", not(target_os = "redox")),
all(feature = "process", any(target_os = "android", target_os = "linux")),
all(feature = "process", linux_android),
all(feature = "fanotify", target_os = "linux")
))]
pub(crate) fn at_rawfd(fd: Option<RawFd>) -> raw::c_int {
Expand Down Expand Up @@ -346,8 +341,7 @@ fn inner_readlink<P: ?Sized + NixPath>(
)
}
#[cfg(not(any(
target_os = "android",
target_os = "linux",
linux_android,
target_os = "redox"
)))]
Some(dirfd) => super::sys::stat::fstatat(
Expand Down Expand Up @@ -406,7 +400,7 @@ pub fn readlinkat<P: ?Sized + NixPath>(
}
}

#[cfg(any(target_os = "android", target_os = "linux", target_os = "freebsd"))]
#[cfg(any(linux_android, target_os = "freebsd"))]
#[cfg(feature = "fs")]
libc_bitflags!(
/// Additional flags for file sealing, which allows for limiting operations on a file.
Expand Down Expand Up @@ -460,14 +454,12 @@ pub enum FcntlArg<'a> {
#[cfg(linux_android)]
F_OFD_GETLK(&'a mut libc::flock),
#[cfg(any(
target_os = "android",
target_os = "linux",
linux_android,
target_os = "freebsd"
))]
F_ADD_SEALS(SealFlag),
#[cfg(any(
target_os = "android",
target_os = "linux",
linux_android,
target_os = "freebsd"
))]
F_GET_SEALS,
Expand Down Expand Up @@ -530,16 +522,14 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
#[cfg(linux_android)]
F_OFD_GETLK(flock) => libc::fcntl(fd, libc::F_OFD_GETLK, flock),
#[cfg(any(
target_os = "android",
target_os = "linux",
linux_android,
target_os = "freebsd"
))]
F_ADD_SEALS(flag) => {
libc::fcntl(fd, libc::F_ADD_SEALS, flag.bits())
}
#[cfg(any(
target_os = "android",
target_os = "linux",
linux_android,
target_os = "freebsd"
))]
F_GET_SEALS => libc::fcntl(fd, libc::F_GET_SEALS),
Expand Down Expand Up @@ -672,7 +662,7 @@ feature! {
// Note: FreeBSD defines the offset argument as "off_t". Linux and Android
// define it as "loff_t". But on both OSes, on all supported platforms, those
// are 64 bits. So Nix uses i64 to make the docs simple and consistent.
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
#[cfg(any(linux_android, target_os = "freebsd"))]
pub fn copy_file_range<Fd1: AsFd, Fd2: AsFd>(
fd_in: Fd1,
off_in: Option<&mut i64>,
Expand Down Expand Up @@ -960,8 +950,7 @@ pub fn fspacectl_all(
}

#[cfg(any(
target_os = "linux",
target_os = "android",
linux_android,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "wasi",
Expand Down Expand Up @@ -1008,13 +997,11 @@ mod posix_fadvise {
}

#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "dragonfly",
linux_android,
freebsdlike,
target_os = "emscripten",
target_os = "fuchsia",
target_os = "wasi",
target_os = "freebsd"
))]
pub fn posix_fallocate(
fd: RawFd,
Expand Down
3 changes: 1 addition & 2 deletions src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ mod os {
}

#[cfg(any(
target_os = "dragonfly", // Since ???
target_os = "freebsd", // Since 10.0
freebsdlike, // FreeBSD since 10.0 DragonFlyBSD since ???
target_os = "illumos", // Since ???
target_os = "netbsd", // Since 6.0
target_os = "openbsd", // Since 5.7
Expand Down
2 changes: 1 addition & 1 deletion src/ifaddrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct InterfaceAddress {
}

cfg_if! {
if #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] {
if #[cfg(any(linux_android, target_os = "emscripten", target_os = "fuchsia"))] {
fn get_ifu_from_sockaddr(info: &libc::ifaddrs) -> *const libc::sockaddr {
info.ifa_ifu
}
Expand Down
10 changes: 2 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ pub mod fcntl;
feature! {
#![feature = "net"]

#[cfg(any(target_os = "android",
#[cfg(any(linux_android,
bsd,
target_os = "linux",
target_os = "illumos"))]
#[deny(missing_docs)]
pub mod ifaddrs;
Expand All @@ -143,12 +142,7 @@ feature! {
#![feature = "mount"]
pub mod mount;
}
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "linux",
target_os = "netbsd"
))]
#[cfg(any(freebsdlike, target_os = "linux", target_os = "netbsd"))]
feature! {
#![feature = "mqueue"]
pub mod mqueue;
Expand Down
2 changes: 1 addition & 1 deletion src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ feature! {
/// so in that case `ppoll` differs from `poll` only in the precision of the
/// timeout argument.
///
#[cfg(any(target_os = "android", freebsdlike, target_os = "linux"))]
#[cfg(any(linux_android, freebsdlike))]
pub fn ppoll(
fds: &mut [PollFd],
timeout: Option<crate::sys::time::TimeSpec>,
Expand Down
14 changes: 2 additions & 12 deletions src/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,10 @@ mod sched_linux_like {
}
}

#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "linux"
))]
#[cfg(any(linux_android, freebsdlike))]
pub use self::sched_affinity::*;

#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "linux"
))]
#[cfg(any(linux_android, freebsdlike))]
mod sched_affinity {
use crate::errno::Errno;
use crate::unistd::Pid;
Expand Down
6 changes: 1 addition & 5 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ impl ClockId {
feature! {
#![feature = "process"]
/// Returns `ClockId` of a `pid` CPU-time clock
#[cfg(any(
freebsdlike,
linux_android,
target_os = "emscripten",
))]
#[cfg(any(freebsdlike, linux_android, target_os = "emscripten"))]
pub fn pid_cpu_clock_id(pid: Pid) -> Result<Self> {
clock_getcpuclockid(pid)
}
Expand Down