Skip to content

Commit ab1d1be

Browse files
authored
refactor: cfg for time/uio/wait (#2221)
1 parent 50c1ec1 commit ab1d1be

File tree

3 files changed

+29
-85
lines changed

3 files changed

+29
-85
lines changed

src/sys/uio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ feature! {
182182
/// [ptrace]: ../ptrace/index.html
183183
/// [`IoSlice`]: https://doc.rust-lang.org/std/io/struct.IoSlice.html
184184
/// [`RemoteIoVec`]: struct.RemoteIoVec.html
185-
#[cfg(all(any(target_os = "linux", target_os = "android"), not(target_env = "uclibc")))]
185+
#[cfg(all(linux_android, not(target_env = "uclibc")))]
186186
pub fn process_vm_writev(
187187
pid: crate::unistd::Pid,
188188
local_iov: &[IoSlice<'_>],
@@ -217,7 +217,7 @@ pub fn process_vm_writev(
217217
/// [`ptrace`]: ../ptrace/index.html
218218
/// [`IoSliceMut`]: https://doc.rust-lang.org/std/io/struct.IoSliceMut.html
219219
/// [`RemoteIoVec`]: struct.RemoteIoVec.html
220-
#[cfg(all(any(target_os = "linux", target_os = "android"), not(target_env = "uclibc")))]
220+
#[cfg(all(linux_android, not(target_env = "uclibc")))]
221221
pub fn process_vm_readv(
222222
pid: crate::unistd::Pid,
223223
local_iov: &mut [IoSliceMut<'_>],

src/sys/wait.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ libc_bitflags!(
2424
/// [`SIGSTOP`](crate::sys::signal::Signal::SIGSTOP) signal.
2525
WUNTRACED;
2626
/// Report the status of selected processes which have terminated.
27-
#[cfg(any(target_os = "android",
27+
#[cfg(any(linux_android,
28+
apple_targets,
2829
target_os = "freebsd",
2930
target_os = "haiku",
30-
apple_targets,
31-
target_os = "linux",
3231
target_os = "redox",
3332
target_os = "netbsd"))]
3433
WEXITED;
@@ -37,31 +36,29 @@ libc_bitflags!(
3736
/// [`SIGCONT`](crate::sys::signal::Signal::SIGCONT) signal.
3837
WCONTINUED;
3938
/// An alias for WUNTRACED.
40-
#[cfg(any(target_os = "android",
39+
#[cfg(any(linux_android,
40+
apple_targets,
4141
target_os = "freebsd",
4242
target_os = "haiku",
43-
apple_targets,
44-
target_os = "linux",
4543
target_os = "redox",
4644
target_os = "netbsd"))]
4745
WSTOPPED;
4846
/// Don't reap, just poll status.
49-
#[cfg(any(target_os = "android",
47+
#[cfg(any(linux_android,
48+
apple_targets,
5049
target_os = "freebsd",
5150
target_os = "haiku",
52-
apple_targets,
53-
target_os = "linux",
5451
target_os = "redox",
5552
target_os = "netbsd"))]
5653
WNOWAIT;
5754
/// Don't wait on children of other threads in this group
58-
#[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))]
55+
#[cfg(any(linux_android, target_os = "redox"))]
5956
__WNOTHREAD;
6057
/// Wait on all children, regardless of type
61-
#[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))]
58+
#[cfg(any(linux_android, target_os = "redox"))]
6259
__WALL;
6360
/// Wait for "clone" children only.
64-
#[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))]
61+
#[cfg(any(linux_android, target_os = "redox"))]
6562
__WCLONE;
6663
}
6764
);
@@ -205,7 +202,7 @@ impl WaitStatus {
205202
WaitStatus::Signaled(pid, term_signal(status)?, dumped_core(status))
206203
} else if stopped(status) {
207204
cfg_if! {
208-
if #[cfg(any(target_os = "android", target_os = "linux"))] {
205+
if #[cfg(linux_android)] {
209206
fn decode_stopped(pid: Pid, status: i32) -> Result<WaitStatus> {
210207
let status_additional = stop_additional(status);
211208
Ok(if syscall_stop(status) {

src/time.rs

Lines changed: 17 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
use crate::sys::time::TimeSpec;
2-
#[cfg(any(
3-
target_os = "freebsd",
4-
target_os = "dragonfly",
5-
target_os = "linux",
6-
target_os = "android",
7-
target_os = "emscripten",
8-
))]
2+
#[cfg(any(freebsdlike, linux_android, target_os = "emscripten"))]
93
#[cfg(feature = "process")]
104
use crate::unistd::Pid;
115
use crate::{Errno, Result};
@@ -29,10 +23,8 @@ impl ClockId {
2923
#![feature = "process"]
3024
/// Returns `ClockId` of a `pid` CPU-time clock
3125
#[cfg(any(
32-
target_os = "freebsd",
33-
target_os = "dragonfly",
34-
target_os = "linux",
35-
target_os = "android",
26+
freebsdlike,
27+
linux_android,
3628
target_os = "emscripten",
3729
))]
3830
pub fn pid_cpu_clock_id(pid: Pid) -> Result<Self> {
@@ -62,28 +54,13 @@ impl ClockId {
6254
self.0
6355
}
6456

65-
#[cfg(any(
66-
target_os = "android",
67-
target_os = "emscripten",
68-
target_os = "fuchsia",
69-
target_os = "linux"
70-
))]
57+
#[cfg(any(linux_android, target_os = "emscripten", target_os = "fuchsia"))]
7158
pub const CLOCK_BOOTTIME: ClockId = ClockId(libc::CLOCK_BOOTTIME);
72-
#[cfg(any(
73-
target_os = "android",
74-
target_os = "emscripten",
75-
target_os = "fuchsia",
76-
target_os = "linux"
77-
))]
59+
#[cfg(any(linux_android, target_os = "emscripten", target_os = "fuchsia"))]
7860
pub const CLOCK_BOOTTIME_ALARM: ClockId =
7961
ClockId(libc::CLOCK_BOOTTIME_ALARM);
8062
pub const CLOCK_MONOTONIC: ClockId = ClockId(libc::CLOCK_MONOTONIC);
81-
#[cfg(any(
82-
target_os = "android",
83-
target_os = "emscripten",
84-
target_os = "fuchsia",
85-
target_os = "linux"
86-
))]
63+
#[cfg(any(linux_android, target_os = "emscripten", target_os = "fuchsia"))]
8764
pub const CLOCK_MONOTONIC_COARSE: ClockId =
8865
ClockId(libc::CLOCK_MONOTONIC_COARSE);
8966
#[cfg(freebsdlike)]
@@ -92,42 +69,25 @@ impl ClockId {
9269
#[cfg(freebsdlike)]
9370
pub const CLOCK_MONOTONIC_PRECISE: ClockId =
9471
ClockId(libc::CLOCK_MONOTONIC_PRECISE);
95-
#[cfg(any(
96-
target_os = "android",
97-
target_os = "emscripten",
98-
target_os = "fuchsia",
99-
target_os = "linux"
100-
))]
72+
#[cfg(any(linux_android, target_os = "emscripten", target_os = "fuchsia"))]
10173
pub const CLOCK_MONOTONIC_RAW: ClockId = ClockId(libc::CLOCK_MONOTONIC_RAW);
10274
#[cfg(any(
103-
target_os = "android",
75+
linux_android,
76+
apple_targets,
77+
freebsdlike,
10478
target_os = "emscripten",
10579
target_os = "fuchsia",
106-
apple_targets,
107-
target_os = "freebsd",
108-
target_os = "dragonfly",
10980
target_os = "redox",
110-
target_os = "linux"
11181
))]
11282
pub const CLOCK_PROCESS_CPUTIME_ID: ClockId =
11383
ClockId(libc::CLOCK_PROCESS_CPUTIME_ID);
11484
#[cfg(freebsdlike)]
11585
pub const CLOCK_PROF: ClockId = ClockId(libc::CLOCK_PROF);
11686
pub const CLOCK_REALTIME: ClockId = ClockId(libc::CLOCK_REALTIME);
117-
#[cfg(any(
118-
target_os = "android",
119-
target_os = "emscripten",
120-
target_os = "fuchsia",
121-
target_os = "linux"
122-
))]
87+
#[cfg(any(linux_android, target_os = "emscripten", target_os = "fuchsia"))]
12388
pub const CLOCK_REALTIME_ALARM: ClockId =
12489
ClockId(libc::CLOCK_REALTIME_ALARM);
125-
#[cfg(any(
126-
target_os = "android",
127-
target_os = "emscripten",
128-
target_os = "fuchsia",
129-
target_os = "linux"
130-
))]
90+
#[cfg(any(linux_android, target_os = "emscripten", target_os = "fuchsia"))]
13191
pub const CLOCK_REALTIME_COARSE: ClockId =
13292
ClockId(libc::CLOCK_REALTIME_COARSE);
13393
#[cfg(freebsdlike)]
@@ -143,21 +103,14 @@ impl ClockId {
143103
all(target_os = "linux", target_env = "musl")
144104
))]
145105
pub const CLOCK_SGI_CYCLE: ClockId = ClockId(libc::CLOCK_SGI_CYCLE);
146-
#[cfg(any(
147-
target_os = "android",
148-
target_os = "emscripten",
149-
target_os = "fuchsia",
150-
target_os = "linux"
151-
))]
106+
#[cfg(any(linux_android, target_os = "emscripten", target_os = "fuchsia"))]
152107
pub const CLOCK_TAI: ClockId = ClockId(libc::CLOCK_TAI);
153108
#[cfg(any(
154-
target_os = "android",
109+
linux_android,
110+
apple_targets,
111+
freebsdlike,
155112
target_os = "emscripten",
156113
target_os = "fuchsia",
157-
apple_targets,
158-
target_os = "freebsd",
159-
target_os = "dragonfly",
160-
target_os = "linux"
161114
))]
162115
pub const CLOCK_THREAD_CPUTIME_ID: ClockId =
163116
ClockId(libc::CLOCK_THREAD_CPUTIME_ID);
@@ -224,13 +177,7 @@ pub fn clock_settime(clock_id: ClockId, timespec: TimeSpec) -> Result<()> {
224177

225178
/// Get the clock id of the specified process id, (see
226179
/// [clock_getcpuclockid(3)](https://pubs.opengroup.org/onlinepubs/009695399/functions/clock_getcpuclockid.html)).
227-
#[cfg(any(
228-
target_os = "freebsd",
229-
target_os = "dragonfly",
230-
target_os = "linux",
231-
target_os = "android",
232-
target_os = "emscripten",
233-
))]
180+
#[cfg(any(freebsdlike, linux_android, target_os = "emscripten"))]
234181
#[cfg(feature = "process")]
235182
#[cfg_attr(docsrs, doc(cfg(feature = "process")))]
236183
pub fn clock_getcpuclockid(pid: Pid) -> Result<ClockId> {

0 commit comments

Comments
 (0)