Skip to content

Commit 2f810de

Browse files
authored
refactor: cfg for fcntl/fetures/ifaddrs/lib/poll/sched/time (#2215)
* refactor: cfg for fcntl/fetures/ifaddrs/lib/poll/sched/time * revert the wrong change
1 parent e411540 commit 2f810de

File tree

7 files changed

+33
-67
lines changed

7 files changed

+33
-67
lines changed

src/fcntl.rs

+25-38
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ use std::os::unix::io::RawFd;
2222
all(target_os = "freebsd", target_arch = "x86_64"),
2323
))]
2424
use std::path::PathBuf;
25-
#[cfg(any(
26-
target_os = "android",
27-
target_os = "freebsd",
28-
target_os = "linux"
29-
))]
25+
#[cfg(any(linux_android, target_os = "freebsd"))]
3026
use std::{
3127
os::unix::io::{AsFd, AsRawFd},
3228
ptr,
@@ -36,8 +32,7 @@ use std::{
3632
use crate::{sys::stat::Mode, NixPath, Result};
3733

3834
#[cfg(any(
39-
target_os = "linux",
40-
target_os = "android",
35+
linux_android,
4136
target_os = "emscripten",
4237
target_os = "fuchsia",
4338
target_os = "wasi",
@@ -81,10 +76,11 @@ libc_bitflags!(
8176
/// Open the file in append-only mode.
8277
O_APPEND;
8378
/// Generate a signal when input or output becomes possible.
84-
#[cfg(not(any(target_os = "aix",
85-
target_os = "illumos",
86-
target_os = "solaris",
87-
target_os = "haiku")))]
79+
#[cfg(not(any(
80+
solarish,
81+
target_os = "aix",
82+
target_os = "haiku"
83+
)))]
8884
O_ASYNC;
8985
/// Closes the file descriptor once an `execve` call is made.
9086
///
@@ -93,19 +89,18 @@ libc_bitflags!(
9389
/// Create the file if it does not exist.
9490
O_CREAT;
9591
/// Try to minimize cache effects of the I/O for this file.
96-
#[cfg(any(target_os = "android",
97-
target_os = "dragonfly",
98-
target_os = "freebsd",
99-
target_os = "linux",
100-
target_os = "netbsd"))]
92+
#[cfg(any(
93+
freebsdlike,
94+
linux_android,
95+
target_os = "netbsd"
96+
))]
10197
O_DIRECT;
10298
/// If the specified path isn't a directory, fail.
10399
#[cfg(not(solarish))]
104100
O_DIRECTORY;
105101
/// Implicitly follow each `write()` with an `fdatasync()`.
106-
#[cfg(any(target_os = "android",
102+
#[cfg(any(linux_android,
107103
apple_targets,
108-
target_os = "linux",
109104
target_os = "netbsd",
110105
target_os = "openbsd"))]
111106
O_DSYNC;
@@ -144,7 +139,7 @@ libc_bitflags!(
144139
/// Obtain a file descriptor for low-level access.
145140
///
146141
/// The file itself is not opened and other file operations will fail.
147-
#[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))]
142+
#[cfg(any(linux_android, target_os = "redox"))]
148143
O_PATH;
149144
/// Only allow reading.
150145
///
@@ -184,7 +179,7 @@ libc_bitflags!(
184179
/// Computes the raw fd consumed by a function of the form `*at`.
185180
#[cfg(any(
186181
all(feature = "fs", not(target_os = "redox")),
187-
all(feature = "process", any(target_os = "android", target_os = "linux")),
182+
all(feature = "process", linux_android),
188183
all(feature = "fanotify", target_os = "linux")
189184
))]
190185
pub(crate) fn at_rawfd(fd: Option<RawFd>) -> raw::c_int {
@@ -346,8 +341,7 @@ fn inner_readlink<P: ?Sized + NixPath>(
346341
)
347342
}
348343
#[cfg(not(any(
349-
target_os = "android",
350-
target_os = "linux",
344+
linux_android,
351345
target_os = "redox"
352346
)))]
353347
Some(dirfd) => super::sys::stat::fstatat(
@@ -406,7 +400,7 @@ pub fn readlinkat<P: ?Sized + NixPath>(
406400
}
407401
}
408402

409-
#[cfg(any(target_os = "android", target_os = "linux", target_os = "freebsd"))]
403+
#[cfg(any(linux_android, target_os = "freebsd"))]
410404
#[cfg(feature = "fs")]
411405
libc_bitflags!(
412406
/// Additional flags for file sealing, which allows for limiting operations on a file.
@@ -460,14 +454,12 @@ pub enum FcntlArg<'a> {
460454
#[cfg(linux_android)]
461455
F_OFD_GETLK(&'a mut libc::flock),
462456
#[cfg(any(
463-
target_os = "android",
464-
target_os = "linux",
457+
linux_android,
465458
target_os = "freebsd"
466459
))]
467460
F_ADD_SEALS(SealFlag),
468461
#[cfg(any(
469-
target_os = "android",
470-
target_os = "linux",
462+
linux_android,
471463
target_os = "freebsd"
472464
))]
473465
F_GET_SEALS,
@@ -530,16 +522,14 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
530522
#[cfg(linux_android)]
531523
F_OFD_GETLK(flock) => libc::fcntl(fd, libc::F_OFD_GETLK, flock),
532524
#[cfg(any(
533-
target_os = "android",
534-
target_os = "linux",
525+
linux_android,
535526
target_os = "freebsd"
536527
))]
537528
F_ADD_SEALS(flag) => {
538529
libc::fcntl(fd, libc::F_ADD_SEALS, flag.bits())
539530
}
540531
#[cfg(any(
541-
target_os = "android",
542-
target_os = "linux",
532+
linux_android,
543533
target_os = "freebsd"
544534
))]
545535
F_GET_SEALS => libc::fcntl(fd, libc::F_GET_SEALS),
@@ -672,7 +662,7 @@ feature! {
672662
// Note: FreeBSD defines the offset argument as "off_t". Linux and Android
673663
// define it as "loff_t". But on both OSes, on all supported platforms, those
674664
// are 64 bits. So Nix uses i64 to make the docs simple and consistent.
675-
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
665+
#[cfg(any(linux_android, target_os = "freebsd"))]
676666
pub fn copy_file_range<Fd1: AsFd, Fd2: AsFd>(
677667
fd_in: Fd1,
678668
off_in: Option<&mut i64>,
@@ -960,8 +950,7 @@ pub fn fspacectl_all(
960950
}
961951

962952
#[cfg(any(
963-
target_os = "linux",
964-
target_os = "android",
953+
linux_android,
965954
target_os = "emscripten",
966955
target_os = "fuchsia",
967956
target_os = "wasi",
@@ -1008,13 +997,11 @@ mod posix_fadvise {
1008997
}
1009998

1010999
#[cfg(any(
1011-
target_os = "linux",
1012-
target_os = "android",
1013-
target_os = "dragonfly",
1000+
linux_android,
1001+
freebsdlike,
10141002
target_os = "emscripten",
10151003
target_os = "fuchsia",
10161004
target_os = "wasi",
1017-
target_os = "freebsd"
10181005
))]
10191006
pub fn posix_fallocate(
10201007
fd: RawFd,

src/features.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ mod os {
9898
}
9999

100100
#[cfg(any(
101-
target_os = "dragonfly", // Since ???
102-
target_os = "freebsd", // Since 10.0
101+
freebsdlike, // FreeBSD since 10.0 DragonFlyBSD since ???
103102
target_os = "illumos", // Since ???
104103
target_os = "netbsd", // Since 6.0
105104
target_os = "openbsd", // Since 5.7

src/ifaddrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct InterfaceAddress {
3333
}
3434

3535
cfg_if! {
36-
if #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "linux"))] {
36+
if #[cfg(any(linux_android, target_os = "emscripten", target_os = "fuchsia"))] {
3737
fn get_ifu_from_sockaddr(info: &libc::ifaddrs) -> *const libc::sockaddr {
3838
info.ifa_ifu
3939
}

src/lib.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ pub mod fcntl;
123123
feature! {
124124
#![feature = "net"]
125125

126-
#[cfg(any(target_os = "android",
126+
#[cfg(any(linux_android,
127127
bsd,
128-
target_os = "linux",
129128
target_os = "illumos"))]
130129
#[deny(missing_docs)]
131130
pub mod ifaddrs;
@@ -143,12 +142,7 @@ feature! {
143142
#![feature = "mount"]
144143
pub mod mount;
145144
}
146-
#[cfg(any(
147-
target_os = "dragonfly",
148-
target_os = "freebsd",
149-
target_os = "linux",
150-
target_os = "netbsd"
151-
))]
145+
#[cfg(any(freebsdlike, target_os = "linux", target_os = "netbsd"))]
152146
feature! {
153147
#![feature = "mqueue"]
154148
pub mod mqueue;

src/poll.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ feature! {
224224
/// so in that case `ppoll` differs from `poll` only in the precision of the
225225
/// timeout argument.
226226
///
227-
#[cfg(any(target_os = "android", freebsdlike, target_os = "linux"))]
227+
#[cfg(any(linux_android, freebsdlike))]
228228
pub fn ppoll(
229229
fds: &mut [PollFd],
230230
timeout: Option<crate::sys::time::TimeSpec>,

src/sched.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,10 @@ mod sched_linux_like {
152152
}
153153
}
154154

155-
#[cfg(any(
156-
target_os = "android",
157-
target_os = "dragonfly",
158-
target_os = "freebsd",
159-
target_os = "linux"
160-
))]
155+
#[cfg(any(linux_android, freebsdlike))]
161156
pub use self::sched_affinity::*;
162157

163-
#[cfg(any(
164-
target_os = "android",
165-
target_os = "dragonfly",
166-
target_os = "freebsd",
167-
target_os = "linux"
168-
))]
158+
#[cfg(any(linux_android, freebsdlike))]
169159
mod sched_affinity {
170160
use crate::errno::Errno;
171161
use crate::unistd::Pid;

src/time.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ impl ClockId {
2222
feature! {
2323
#![feature = "process"]
2424
/// Returns `ClockId` of a `pid` CPU-time clock
25-
#[cfg(any(
26-
freebsdlike,
27-
linux_android,
28-
target_os = "emscripten",
29-
))]
25+
#[cfg(any(freebsdlike, linux_android, target_os = "emscripten"))]
3026
pub fn pid_cpu_clock_id(pid: Pid) -> Result<Self> {
3127
clock_getcpuclockid(pid)
3228
}

0 commit comments

Comments
 (0)