Skip to content

Commit 0c8da48

Browse files
authored
refactor: cfg for aio/epoll/event/mman/mod/resource/sendfile/signal (#2218)
1 parent 54ded47 commit 0c8da48

File tree

6 files changed

+46
-134
lines changed

6 files changed

+46
-134
lines changed

src/sys/event.rs

+12-45
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,7 @@ impl Kqueue {
7878
}
7979
}
8080

81-
#[cfg(any(
82-
target_os = "dragonfly",
83-
target_os = "freebsd",
84-
apple_targets,
85-
target_os = "openbsd"
86-
))]
81+
#[cfg(any(freebsdlike, apple_targets, target_os = "openbsd"))]
8782
type type_of_udata = *mut libc::c_void;
8883
#[cfg(target_os = "netbsd")]
8984
type type_of_udata = intptr_t;
@@ -108,9 +103,7 @@ libc_enum! {
108103
/// Takes a descriptor as the identifier, and returns whenever one of
109104
/// the specified exceptional conditions has occurred on the descriptor.
110105
EVFILT_EXCEPT,
111-
#[cfg(any(target_os = "dragonfly",
112-
target_os = "freebsd",
113-
apple_targets))]
106+
#[cfg(any(freebsdlike, apple_targets))]
114107
/// Establishes a file system monitor.
115108
EVFILT_FS,
116109
#[cfg(target_os = "freebsd")]
@@ -142,9 +135,7 @@ libc_enum! {
142135
EVFILT_SIGNAL,
143136
/// Establishes a timer and notifies when the timer expires.
144137
EVFILT_TIMER,
145-
#[cfg(any(target_os = "dragonfly",
146-
target_os = "freebsd",
147-
apple_targets))]
138+
#[cfg(any(freebsdlike, apple_targets))]
148139
/// Notifies only when explicitly requested by the user.
149140
EVFILT_USER,
150141
#[cfg(apple_targets)]
@@ -159,12 +150,7 @@ libc_enum! {
159150
impl TryFrom<type_of_event_filter>
160151
}
161152

162-
#[cfg(any(
163-
target_os = "dragonfly",
164-
target_os = "freebsd",
165-
apple_targets,
166-
target_os = "openbsd"
167-
))]
153+
#[cfg(any(freebsdlike, apple_targets, target_os = "openbsd"))]
168154
#[doc(hidden)]
169155
pub type type_of_event_flag = u16;
170156
#[cfg(target_os = "netbsd")]
@@ -244,34 +230,22 @@ libc_bitflags!(
244230
NOTE_EXITSTATUS;
245231
#[allow(missing_docs)]
246232
NOTE_EXTEND;
247-
#[cfg(any(apple_targets,
248-
target_os = "freebsd",
249-
target_os = "dragonfly"))]
233+
#[cfg(any(apple_targets, freebsdlike))]
250234
#[allow(missing_docs)]
251235
NOTE_FFAND;
252-
#[cfg(any(apple_targets,
253-
target_os = "freebsd",
254-
target_os = "dragonfly"))]
236+
#[cfg(any(apple_targets, freebsdlike))]
255237
#[allow(missing_docs)]
256238
NOTE_FFCOPY;
257-
#[cfg(any(apple_targets,
258-
target_os = "freebsd",
259-
target_os = "dragonfly"))]
239+
#[cfg(any(apple_targets, freebsdlike))]
260240
#[allow(missing_docs)]
261241
NOTE_FFCTRLMASK;
262-
#[cfg(any(apple_targets,
263-
target_os = "freebsd",
264-
target_os = "dragonfly"))]
242+
#[cfg(any(apple_targets, freebsdlike))]
265243
#[allow(missing_docs)]
266244
NOTE_FFLAGSMASK;
267-
#[cfg(any(apple_targets,
268-
target_os = "freebsd",
269-
target_os = "dragonfly"))]
245+
#[cfg(any(apple_targets, freebsdlike))]
270246
#[allow(missing_docs)]
271247
NOTE_FFNOP;
272-
#[cfg(any(apple_targets,
273-
target_os = "freebsd",
274-
target_os = "dragonfly"))]
248+
#[cfg(any(apple_targets, freebsdlike))]
275249
#[allow(missing_docs)]
276250
NOTE_FFOR;
277251
#[allow(missing_docs)]
@@ -314,9 +288,7 @@ libc_bitflags!(
314288
NOTE_TRACK;
315289
#[allow(missing_docs)]
316290
NOTE_TRACKERR;
317-
#[cfg(any(apple_targets,
318-
target_os = "freebsd",
319-
target_os = "dragonfly"))]
291+
#[cfg(any(apple_targets, freebsdlike))]
320292
#[allow(missing_docs)]
321293
NOTE_TRIGGER;
322294
#[cfg(target_os = "openbsd")]
@@ -434,12 +406,7 @@ pub fn kevent(
434406
kq.kevent(changelist, eventlist, Some(timeout))
435407
}
436408

437-
#[cfg(any(
438-
apple_targets,
439-
target_os = "freebsd",
440-
target_os = "dragonfly",
441-
target_os = "openbsd"
442-
))]
409+
#[cfg(any(apple_targets, freebsdlike, target_os = "openbsd"))]
443410
type type_of_nchanges = c_int;
444411
#[cfg(target_os = "netbsd")]
445412
type type_of_nchanges = size_t;

src/sys/mman.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ libc_bitflags! {
5757
/// The mapping is not backed by any file.
5858
MAP_ANONYMOUS;
5959
/// Put the mapping into the first 2GB of the process address space.
60-
#[cfg(any(all(any(target_os = "android", target_os = "linux"),
60+
#[cfg(any(all(linux_android,
6161
any(target_arch = "x86", target_arch = "x86_64")),
6262
all(target_os = "linux", target_env = "musl", any(target_arch = "x86", target_arch = "x86_64")),
6363
all(target_os = "freebsd", target_pointer_width = "64")))]
@@ -140,7 +140,7 @@ libc_bitflags! {
140140
#[cfg(any(freebsdlike, target_os = "netbsd", target_os = "openbsd"))]
141141
MAP_HASSEMAPHORE;
142142
/// Region grows down, like a stack.
143-
#[cfg(any(target_os = "android", freebsdlike, target_os = "linux", target_os = "openbsd"))]
143+
#[cfg(any(linux_android, freebsdlike, target_os = "openbsd"))]
144144
MAP_STACK;
145145
/// Pages in this mapping are not retained in the kernel's memory cache.
146146
#[cfg(apple_targets)]

src/sys/mod.rs

+7-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Mostly platform-specific functionality
22
#[cfg(any(
3-
target_os = "dragonfly",
4-
target_os = "freebsd",
3+
freebsdlike,
54
all(target_os = "linux", not(target_env = "uclibc")),
65
apple_targets,
76
target_os = "netbsd"
@@ -32,19 +31,13 @@ feature! {
3231
pub mod fanotify;
3332
}
3433

35-
#[cfg(any(
36-
bsd,
37-
target_os = "android",
38-
target_os = "linux",
39-
target_os = "redox",
40-
target_os = "illumos",
41-
))]
34+
#[cfg(any(bsd, linux_android, target_os = "redox", target_os = "illumos"))]
4235
#[cfg(feature = "ioctl")]
4336
#[cfg_attr(docsrs, doc(cfg(feature = "ioctl")))]
4437
#[macro_use]
4538
pub mod ioctl;
4639

47-
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
40+
#[cfg(any(linux_android, target_os = "freebsd"))]
4841
feature! {
4942
#![feature = "fs"]
5043
pub mod memfd;
@@ -74,10 +67,8 @@ feature! {
7467
}
7568

7669
#[cfg(any(
77-
target_os = "android",
78-
target_os = "dragonfly",
79-
target_os = "freebsd",
80-
target_os = "linux",
70+
linux_android,
71+
freebsdlike,
8172
target_os = "macos",
8273
target_os = "netbsd",
8374
target_os = "openbsd"
@@ -116,15 +107,7 @@ feature! {
116107
pub mod select;
117108
}
118109

119-
#[cfg(any(
120-
target_os = "android",
121-
target_os = "dragonfly",
122-
target_os = "freebsd",
123-
apple_targets,
124-
target_os = "linux",
125-
target_os = "solaris",
126-
target_os = "illumos",
127-
))]
110+
#[cfg(any(linux_android, freebsdlike, apple_targets, solarish))]
128111
feature! {
129112
#![feature = "zerocopy"]
130113
pub mod sendfile;
@@ -151,14 +134,7 @@ feature! {
151134
pub mod stat;
152135
}
153136

154-
#[cfg(any(
155-
target_os = "android",
156-
target_os = "dragonfly",
157-
target_os = "freebsd",
158-
apple_targets,
159-
target_os = "linux",
160-
target_os = "openbsd"
161-
))]
137+
#[cfg(any(linux_android, freebsdlike, apple_targets, target_os = "openbsd"))]
162138
feature! {
163139
#![feature = "fs"]
164140
pub mod statfs;

src/sys/resource.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ libc_enum! {
7575
RLIMIT_LOCKS,
7676

7777
#[cfg(any(
78-
target_os = "android",
78+
linux_android,
7979
target_os = "freebsd",
8080
target_os = "openbsd",
81-
target_os = "linux",
8281
target_os = "netbsd"
8382
))]
8483
/// The maximum size (in bytes) which a process may lock into memory
@@ -96,11 +95,10 @@ libc_enum! {
9695
RLIMIT_NICE,
9796

9897
#[cfg(any(
99-
target_os = "android",
98+
linux_android,
10099
target_os = "freebsd",
101100
target_os = "netbsd",
102101
target_os = "openbsd",
103-
target_os = "linux",
104102
target_os = "aix",
105103
))]
106104
/// The maximum number of simultaneous processes for this user id.
@@ -111,11 +109,10 @@ libc_enum! {
111109
/// create.
112110
RLIMIT_NPTS,
113111

114-
#[cfg(any(target_os = "android",
112+
#[cfg(any(linux_android,
115113
target_os = "freebsd",
116114
target_os = "netbsd",
117115
target_os = "openbsd",
118-
target_os = "linux",
119116
target_os = "aix",
120117
))]
121118
/// When there is memory pressure and swap is available, prioritize

src/sys/sendfile.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ use crate::Result;
2222
///
2323
/// For more information, see [the sendfile(2) man page.](https://man7.org/linux/man-pages/man2/sendfile.2.html) for Linux,
2424
/// see [the sendfile(2) man page.](https://docs.oracle.com/cd/E88353_01/html/E37843/sendfile-3c.html) for Solaris.
25-
#[cfg(any(
26-
target_os = "android",
27-
target_os = "linux",
28-
target_os = "solaris",
29-
target_os = "illumos",
30-
))]
25+
#[cfg(any(linux_android, solarish))]
3126
pub fn sendfile<F1: AsFd, F2: AsFd>(
3227
out_fd: F1,
3328
in_fd: F2,
@@ -82,9 +77,7 @@ pub fn sendfile64<F1: AsFd, F2: AsFd>(
8277
}
8378

8479
cfg_if! {
85-
if #[cfg(any(target_os = "dragonfly",
86-
target_os = "freebsd",
87-
apple_targets,))] {
80+
if #[cfg(any(freebsdlike, apple_targets))] {
8881
use std::io::IoSlice;
8982

9083
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)