From bbcee88a75b30666b06c3fe1d4522391bc0e119d Mon Sep 17 00:00:00 2001 From: Luis Cruz Date: Wed, 12 Jul 2023 12:41:50 +0100 Subject: [PATCH] Add apple tvos support --- Cargo.toml | 3 + build.rs | 11 ++ src/dir.rs | 3 +- src/errno.rs | 116 ++++++----------- src/fcntl.rs | 42 ++++--- src/features.rs | 3 +- src/ifaddrs.rs | 8 +- src/lib.rs | 3 +- src/mount/linux.rs | 2 +- src/net/if_.rs | 35 ++---- src/sys/aio.rs | 11 +- src/sys/event.rs | 78 ++++++------ src/sys/inotify.rs | 14 ++- src/sys/ioctl/mod.rs | 6 +- src/sys/mman.rs | 25 ++-- src/sys/mod.rs | 15 +-- src/sys/prctl.rs | 14 ++- src/sys/resource.rs | 6 +- src/sys/sendfile.rs | 5 +- src/sys/signalfd.rs | 30 ++--- src/sys/socket/addr.rs | 253 ++++++++++++++++++++------------------ src/sys/socket/mod.rs | 135 ++++++++------------ src/sys/socket/sockopt.rs | 35 ++---- src/sys/stat.rs | 24 ++-- src/sys/statfs.rs | 22 ++-- src/sys/termios.rs | 118 ++++++------------ src/sys/uio.rs | 18 ++- src/sys/utsname.rs | 2 +- src/sys/wait.rs | 13 +- src/time.rs | 20 +-- src/unistd.rs | 189 ++++++++++------------------ test/sys/mod.rs | 3 +- test/sys/test_aio_drop.rs | 3 +- test/sys/test_ioctl.rs | 3 +- test/sys/test_socket.rs | 14 +-- test/sys/test_sockopt.rs | 18 +-- test/test.rs | 3 +- test/test_fcntl.rs | 9 +- test/test_sendfile.rs | 8 +- test/test_stat.rs | 12 +- test/test_unistd.rs | 31 ++--- 41 files changed, 575 insertions(+), 788 deletions(-) create mode 100644 build.rs diff --git a/Cargo.toml b/Cargo.toml index 5a7806075a..8cd6e3a09e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,6 +83,9 @@ caps = "0.5.3" [target.'cfg(target_os = "freebsd")'.dev-dependencies] sysctl = "0.4" +[build-dependencies] +cfg_aliases = "0.1.1" + [[test]] name = "test" path = "test/test.rs" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000000..15847184f2 --- /dev/null +++ b/build.rs @@ -0,0 +1,11 @@ +use cfg_aliases::cfg_aliases; + +fn main() { + cfg_aliases! { + ios: { target_os = "ios" }, + macos: { target_os = "macos" }, + watchos: { target_os = "watchos" }, + tvos: { target_os = "tvos" }, + apple_targets: { any(ios, macos, watchos, tvos) }, + } +} diff --git a/src/dir.rs b/src/dir.rs index bdec58bd1b..6dec1525d5 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -230,10 +230,9 @@ impl Entry { target_os = "fuchsia", target_os = "haiku", target_os = "illumos", - target_os = "ios", + apple_targets, target_os = "l4re", target_os = "linux", - target_os = "macos", target_os = "solaris"))] { self.0.d_ino as u64 } else { diff --git a/src/errno.rs b/src/errno.rs index 50b35248f8..6b69ccac00 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -8,8 +8,7 @@ pub use self::consts::*; cfg_if! { if #[cfg(any(target_os = "freebsd", - target_os = "ios", - target_os = "macos"))] { + apple_targets,))] { unsafe fn errno_location() -> *mut c_int { libc::__error() } @@ -796,20 +795,18 @@ fn desc(errno: Errno) -> &'static str { ECAPMODE => "Not permitted in capability mode", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd" ))] ENEEDAUTH => "Need authenticator", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd", target_os = "redox", @@ -819,10 +816,9 @@ fn desc(errno: Errno) -> &'static str { EOVERFLOW => "Value too large to be stored in data type", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "netbsd", target_os = "redox", target_os = "haiku" @@ -830,10 +826,9 @@ fn desc(errno: Errno) -> &'static str { EILSEQ => "Illegal byte sequence", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd", target_os = "haiku" @@ -841,10 +836,9 @@ fn desc(errno: Errno) -> &'static str { ENOATTR => "Attribute not found", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd", target_os = "redox", @@ -853,10 +847,9 @@ fn desc(errno: Errno) -> &'static str { EBADMSG => "Bad message", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd", target_os = "redox", @@ -865,28 +858,25 @@ fn desc(errno: Errno) -> &'static str { EPROTO => "Protocol error", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd" ))] ENOTRECOVERABLE => "State not recoverable", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd" ))] EOWNERDEAD => "Previous owner died", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd", target_os = "aix", @@ -897,10 +887,9 @@ fn desc(errno: Errno) -> &'static str { ENOTSUP => "Operation not supported", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "aix", target_os = "openbsd", target_os = "netbsd" @@ -908,10 +897,9 @@ fn desc(errno: Errno) -> &'static str { EPROCLIM => "Too many processes", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "aix", target_os = "openbsd", target_os = "netbsd", @@ -920,10 +908,9 @@ fn desc(errno: Errno) -> &'static str { EUSERS => "Too many users", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd", target_os = "redox", @@ -935,10 +922,9 @@ fn desc(errno: Errno) -> &'static str { EDQUOT => "Disc quota exceeded", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd", target_os = "redox", @@ -950,10 +936,9 @@ fn desc(errno: Errno) -> &'static str { ESTALE => "Stale NFS file handle", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "aix", target_os = "openbsd", target_os = "netbsd", @@ -962,80 +947,72 @@ fn desc(errno: Errno) -> &'static str { EREMOTE => "Too many levels of remote in path", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd" ))] EBADRPC => "RPC struct is bad", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd" ))] ERPCMISMATCH => "RPC version wrong", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd" ))] EPROGUNAVAIL => "RPC prog. not avail", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd" ))] EPROGMISMATCH => "Program version wrong", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd" ))] EPROCUNAVAIL => "Bad procedure for program", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd" ))] EFTYPE => "Inappropriate file type or format", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "openbsd", target_os = "netbsd" ))] EAUTH => "Authentication error", #[cfg(any( - target_os = "macos", target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", + apple_targets, target_os = "aix", target_os = "openbsd", target_os = "netbsd", @@ -1043,52 +1020,40 @@ fn desc(errno: Errno) -> &'static str { ))] ECANCELED => "Operation canceled", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] EPWROFF => "Device power is off", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] EDEVERR => "Device error, e.g. paper out", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] EBADEXEC => "Bad executable", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] EBADARCH => "Bad CPU type in executable", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] ESHLIBVERS => "Shared library version mismatch", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] EBADMACHO => "Malformed Macho file", - #[cfg(any( - target_os = "macos", - target_os = "ios", - target_os = "netbsd", - target_os = "haiku" - ))] + #[cfg(any(apple_targets, target_os = "netbsd", target_os = "haiku"))] EMULTIHOP => "Reserved", #[cfg(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "aix", target_os = "netbsd", target_os = "redox" ))] ENODATA => "No message available on STREAM", - #[cfg(any( - target_os = "macos", - target_os = "ios", - target_os = "netbsd", - target_os = "haiku" - ))] + #[cfg(any(apple_targets, target_os = "netbsd", target_os = "haiku"))] ENOLINK => "Reserved", #[cfg(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "aix", target_os = "netbsd", target_os = "redox" @@ -1096,8 +1061,7 @@ fn desc(errno: Errno) -> &'static str { ENOSR => "No STREAM resources", #[cfg(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "aix", target_os = "netbsd", target_os = "redox" @@ -1105,8 +1069,7 @@ fn desc(errno: Errno) -> &'static str { ENOSTR => "Not a STREAM", #[cfg(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "aix", target_os = "netbsd", target_os = "redox" @@ -1114,18 +1077,17 @@ fn desc(errno: Errno) -> &'static str { ETIME => "STREAM ioctl timeout", #[cfg(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "aix", target_os = "illumos", target_os = "solaris" ))] EOPNOTSUPP => "Operation not supported on socket", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] ENOPOLICY => "No such policy registered", - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] EQFULL => "Interface output queue is full", #[cfg(target_os = "openbsd")] @@ -1438,7 +1400,7 @@ mod consts { } } -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(apple_targets)] mod consts { #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(i32)] diff --git a/src/fcntl.rs b/src/fcntl.rs index 2ecd0735c6..aacd1e1675 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -4,8 +4,7 @@ use core::slice; use libc::{self, c_int, c_uint, size_t, ssize_t}; #[cfg(any( target_os = "netbsd", - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "dragonfly", all(target_os = "freebsd", target_arch = "x86_64"), ))] @@ -18,8 +17,7 @@ use std::os::unix::io::RawFd; // For splice and copy_file_range #[cfg(any( target_os = "netbsd", - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "dragonfly", all(target_os = "freebsd", target_arch = "x86_64"), ))] @@ -106,9 +104,8 @@ libc_bitflags!( O_DIRECTORY; /// Implicitly follow each `write()` with an `fdatasync()`. #[cfg(any(target_os = "android", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -122,8 +119,7 @@ libc_bitflags!( /// Open with an exclusive file lock. #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd", target_os = "redox"))] @@ -132,9 +128,8 @@ libc_bitflags!( /// Same as `O_SYNC`. #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, all(target_os = "linux", not(target_env = "musl")), - target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "redox"))] @@ -189,8 +184,7 @@ libc_bitflags!( /// Open with a shared file lock. #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd", target_os = "redox"))] @@ -502,19 +496,23 @@ pub enum FcntlArg<'a> { target_os = "freebsd" ))] F_GET_SEALS, - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] F_FULLFSYNC, - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] F_BARRIERFSYNC, #[cfg(any(target_os = "linux", target_os = "android"))] F_GETPIPE_SZ, #[cfg(any(target_os = "linux", target_os = "android"))] F_SETPIPE_SZ(c_int), - #[cfg(any(target_os = "netbsd", target_os = "dragonfly", target_os = "macos", target_os = "ios"))] + #[cfg(any( + target_os = "netbsd", + target_os = "dragonfly", + apple_targets, + ))] F_GETPATH(&'a mut PathBuf), #[cfg(all(target_os = "freebsd", target_arch = "x86_64"))] F_KINFO(&'a mut PathBuf), - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] F_GETPATH_NOFIRMLINK(&'a mut PathBuf), // TODO: Rest of flags } @@ -570,15 +568,19 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result { target_os = "freebsd" ))] F_GET_SEALS => libc::fcntl(fd, libc::F_GET_SEALS), - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] F_FULLFSYNC => libc::fcntl(fd, libc::F_FULLFSYNC), - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] F_BARRIERFSYNC => libc::fcntl(fd, libc::F_BARRIERFSYNC), #[cfg(any(target_os = "linux", target_os = "android"))] F_GETPIPE_SZ => libc::fcntl(fd, libc::F_GETPIPE_SZ), #[cfg(any(target_os = "linux", target_os = "android"))] F_SETPIPE_SZ(size) => libc::fcntl(fd, libc::F_SETPIPE_SZ, size), - #[cfg(any(target_os = "dragonfly", target_os = "netbsd", target_os = "macos", target_os = "ios"))] + #[cfg(any( + target_os = "dragonfly", + target_os = "netbsd", + apple_targets, + ))] F_GETPATH(path) => { let mut buffer = vec![0; libc::PATH_MAX as usize]; let res = libc::fcntl(fd, libc::F_GETPATH, buffer.as_mut_ptr()); @@ -599,7 +601,7 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result { *path = PathBuf::from(OsString::from(optr.to_str().unwrap())); return Ok(ok_res) }, - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] F_GETPATH_NOFIRMLINK(path) => { let mut buffer = vec![0; libc::PATH_MAX as usize]; let res = libc::fcntl(fd, libc::F_GETPATH_NOFIRMLINK, buffer.as_mut_ptr()); diff --git a/src/features.rs b/src/features.rs index 9e292cbf5d..8aac9ede1e 100644 --- a/src/features.rs +++ b/src/features.rs @@ -114,8 +114,7 @@ mod os { #[cfg(any( target_os = "aix", - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "fuchsia", target_os = "haiku", target_os = "solaris" diff --git a/src/ifaddrs.rs b/src/ifaddrs.rs index e7bf9d0c5a..75795dfe9e 100644 --- a/src/ifaddrs.rs +++ b/src/ifaddrs.rs @@ -4,7 +4,7 @@ //! of interfaces and their associated addresses. use cfg_if::cfg_if; -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple_targets)] use std::convert::TryFrom; use std::ffi; use std::iter::Iterator; @@ -53,7 +53,7 @@ cfg_if! { /// ss_len field to sizeof(sockaddr_storage). This is supposedly valid as all /// members of the sockaddr_storage are "ok" with being zeroed out (there are /// no pointers). -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple_targets)] unsafe fn workaround_xnu_bug(info: &libc::ifaddrs) -> Option { let src_sock = info.ifa_netmask; if src_sock.is_null() { @@ -85,9 +85,9 @@ impl InterfaceAddress { fn from_libc_ifaddrs(info: &libc::ifaddrs) -> InterfaceAddress { let ifname = unsafe { ffi::CStr::from_ptr(info.ifa_name) }; let address = unsafe { SockaddrStorage::from_raw(info.ifa_addr, None) }; - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] let netmask = unsafe { workaround_xnu_bug(info) }; - #[cfg(not(any(target_os = "ios", target_os = "macos")))] + #[cfg(not(apple_targets))] let netmask = unsafe { SockaddrStorage::from_raw(info.ifa_netmask, None) }; let mut addr = InterfaceAddress { diff --git a/src/lib.rs b/src/lib.rs index 959e76e768..fd750a3426 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -124,9 +124,8 @@ feature! { #[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "illumos", target_os = "openbsd"))] diff --git a/src/mount/linux.rs b/src/mount/linux.rs index e987603786..aa166bc9d3 100644 --- a/src/mount/linux.rs +++ b/src/mount/linux.rs @@ -85,7 +85,7 @@ libc_bitflags!( MNT_DETACH; /// Mark the mount point as expired. MNT_EXPIRE; - /// Don't dereference `target` if it is a symlink. + /// Don't dereference `target` if it is a symlink. UMOUNT_NOFOLLOW; } ); diff --git a/src/net/if_.rs b/src/net/if_.rs index 2f13a96d94..6fbe137075 100644 --- a/src/net/if_.rs +++ b/src/net/if_.rs @@ -41,9 +41,8 @@ libc_bitflags!( /// [`netdevice(7)`](https://man7.org/linux/man-pages/man7/netdevice.7.html)) #[cfg(any(target_os = "android", target_os = "fuchsia", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "illumos", target_os = "solaris"))] @@ -60,9 +59,8 @@ libc_bitflags!( target_os = "freebsd", target_os = "fuchsia", target_os = "illumos", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "solaris"))] @@ -84,10 +82,9 @@ libc_bitflags!( IFF_MASTER; /// transmission in progress, tx hardware queue is full #[cfg(any(target_os = "freebsd", - target_os = "macos", + apple_targets, target_os = "netbsd", - target_os = "openbsd", - target_os = "ios"))] + target_os = "openbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] IFF_OACTIVE; /// Protocol code on board. @@ -113,10 +110,9 @@ libc_bitflags!( /// Per link layer defined bit. #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "macos", + apple_targets, target_os = "netbsd", - target_os = "openbsd", - target_os = "ios"))] + target_os = "openbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] IFF_LINK0; /// Multicast using broadcast. @@ -131,10 +127,9 @@ libc_bitflags!( /// Per link layer defined bit. #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "macos", + apple_targets, target_os = "netbsd", - target_os = "openbsd", - target_os = "ios"))] + target_os = "openbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] IFF_LINK1; /// Non-unique address. @@ -149,17 +144,15 @@ libc_bitflags!( /// Per link layer defined bit. #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "macos", + apple_targets, target_os = "netbsd", - target_os = "openbsd", - target_os = "ios"))] + target_os = "openbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] IFF_LINK2; /// Use alternate physical connection. #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "macos", - target_os = "ios"))] + apple_targets,))] #[cfg_attr(docsrs, doc(cfg(all())))] IFF_ALTPHYS; /// DHCP controls interface. @@ -329,9 +322,8 @@ libc_bitflags!( target_os = "dragonfly", target_os = "freebsd", target_os = "fuchsia", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "illumos", @@ -462,9 +454,8 @@ mod if_nameindex { target_os = "dragonfly", target_os = "freebsd", target_os = "fuchsia", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "illumos", diff --git a/src/sys/aio.rs b/src/sys/aio.rs index 3716f4190d..132889e36d 100644 --- a/src/sys/aio.rs +++ b/src/sys/aio.rs @@ -53,9 +53,8 @@ libc_enum! { /// do it like `fsync` O_SYNC, /// on supported operating systems only, do it like `fdatasync` - #[cfg(any(target_os = "ios", + #[cfg(any(apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -1055,7 +1054,8 @@ pub fn aio_suspend( // generic, and accepting arguments like &[AioWrite]. But that would // prevent using aio_suspend to wait on a heterogeneous list of mixed // operations. - let v = list.iter() + let v = list + .iter() .map(|x| x.as_ref() as *const libc::aiocb) .collect::>(); let p = v.as_ptr(); @@ -1175,7 +1175,10 @@ pub fn aio_suspend( /// // notification, we know that all operations are complete. /// assert_eq!(aiow.as_mut().aio_return().unwrap(), WBUF.len()); /// ``` -#[deprecated(since = "0.27.0", note = "https://github.com/nix-rust/nix/issues/2017")] +#[deprecated( + since = "0.27.0", + note = "https://github.com/nix-rust/nix/issues/2017" +)] pub fn lio_listio( mode: LioMode, list: &mut [Pin<&mut dyn AsMut>], diff --git a/src/sys/event.rs b/src/sys/event.rs index 47ea2d027b..4372508499 100644 --- a/src/sys/event.rs +++ b/src/sys/event.rs @@ -81,8 +81,7 @@ impl Kqueue { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "openbsd" ))] type type_of_udata = *mut libc::c_void; @@ -111,8 +110,7 @@ libc_enum! { EVFILT_EXCEPT, #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos"))] + apple_targets))] /// Establishes a file system monitor. EVFILT_FS, #[cfg(target_os = "freebsd")] @@ -120,7 +118,7 @@ libc_enum! { /// # See Also /// [lio_listio(2)](https://www.freebsd.org/cgi/man.cgi?query=lio_listio) EVFILT_LIO, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] /// Mach portsets EVFILT_MACHPORT, /// Notifies when a process performs one or more of the requested @@ -146,11 +144,10 @@ libc_enum! { EVFILT_TIMER, #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos"))] + apple_targets))] /// Notifies only when explicitly requested by the user. EVFILT_USER, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] /// Virtual memory events EVFILT_VM, /// Notifies when a requested event happens on a specified file. @@ -165,8 +162,7 @@ libc_enum! { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "openbsd" ))] #[doc(hidden)] @@ -188,7 +184,7 @@ libc_bitflags! { #[allow(missing_docs)] EV_DISABLE; #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd"))] #[allow(missing_docs)] EV_DISPATCH; @@ -201,7 +197,7 @@ libc_bitflags! { EV_EOF; #[allow(missing_docs)] EV_ERROR; - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] #[allow(missing_docs)] EV_FLAG0; #[allow(missing_docs)] @@ -211,14 +207,14 @@ libc_bitflags! { EV_NODATA; #[allow(missing_docs)] EV_ONESHOT; - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "tvos"))] #[allow(missing_docs)] EV_OOBAND; - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] #[allow(missing_docs)] EV_POLL; #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd"))] #[allow(missing_docs)] EV_RECEIPT; @@ -231,7 +227,7 @@ libc_bitflags!( // that wouldn't simply be repeating the man page. #[allow(missing_docs)] pub struct FilterFlag: u32 { - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] #[allow(missing_docs)] NOTE_ABSOLUTE; #[allow(missing_docs)] @@ -247,43 +243,37 @@ libc_bitflags!( NOTE_EXEC; #[allow(missing_docs)] NOTE_EXIT; - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] #[allow(missing_docs)] NOTE_EXITSTATUS; #[allow(missing_docs)] NOTE_EXTEND; - #[cfg(any(target_os = "macos", - target_os = "ios", + #[cfg(any(apple_targets, target_os = "freebsd", target_os = "dragonfly"))] #[allow(missing_docs)] NOTE_FFAND; - #[cfg(any(target_os = "macos", - target_os = "ios", + #[cfg(any(apple_targets, target_os = "freebsd", target_os = "dragonfly"))] #[allow(missing_docs)] NOTE_FFCOPY; - #[cfg(any(target_os = "macos", - target_os = "ios", + #[cfg(any(apple_targets, target_os = "freebsd", target_os = "dragonfly"))] #[allow(missing_docs)] NOTE_FFCTRLMASK; - #[cfg(any(target_os = "macos", - target_os = "ios", + #[cfg(any(apple_targets, target_os = "freebsd", target_os = "dragonfly"))] #[allow(missing_docs)] NOTE_FFLAGSMASK; - #[cfg(any(target_os = "macos", - target_os = "ios", + #[cfg(any(apple_targets, target_os = "freebsd", target_os = "dragonfly"))] #[allow(missing_docs)] NOTE_FFNOP; - #[cfg(any(target_os = "macos", - target_os = "ios", + #[cfg(any(apple_targets, target_os = "freebsd", target_os = "dragonfly"))] #[allow(missing_docs)] @@ -297,10 +287,12 @@ libc_bitflags!( #[cfg(target_os = "freebsd")] #[allow(missing_docs)] NOTE_MSECONDS; - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] #[allow(missing_docs)] NOTE_NONE; - #[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))] + #[cfg(any( + apple_targets, + target_os = "freebsd"))] #[allow(missing_docs)] NOTE_NSECONDS; #[cfg(target_os = "dragonfly")] @@ -314,18 +306,19 @@ libc_bitflags!( NOTE_RENAME; #[allow(missing_docs)] NOTE_REVOKE; - #[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))] + #[cfg(any( + apple_targets, + target_os = "freebsd"))] #[allow(missing_docs)] NOTE_SECONDS; - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] #[allow(missing_docs)] NOTE_SIGNAL; #[allow(missing_docs)] NOTE_TRACK; #[allow(missing_docs)] NOTE_TRACKERR; - #[cfg(any(target_os = "macos", - target_os = "ios", + #[cfg(any(apple_targets, target_os = "freebsd", target_os = "dragonfly"))] #[allow(missing_docs)] @@ -333,19 +326,21 @@ libc_bitflags!( #[cfg(target_os = "openbsd")] #[allow(missing_docs)] NOTE_TRUNCATE; - #[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd"))] + #[cfg(any( + apple_targets, + target_os = "freebsd"))] #[allow(missing_docs)] NOTE_USECONDS; - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] #[allow(missing_docs)] NOTE_VM_ERROR; - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] #[allow(missing_docs)] NOTE_VM_PRESSURE; - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] #[allow(missing_docs)] NOTE_VM_PRESSURE_SUDDEN_TERMINATE; - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] #[allow(missing_docs)] NOTE_VM_PRESSURE_TERMINATE; #[allow(missing_docs)] @@ -444,8 +439,7 @@ pub fn kevent( } #[cfg(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd" diff --git a/src/sys/inotify.rs b/src/sys/inotify.rs index c1b15f9bf6..a3a037689f 100644 --- a/src/sys/inotify.rs +++ b/src/sys/inotify.rs @@ -143,7 +143,9 @@ impl Inotify { pub fn init(flags: InitFlags) -> Result { let res = Errno::result(unsafe { libc::inotify_init1(flags.bits()) }); - res.map(|fd| Inotify { fd: unsafe { OwnedFd::from_raw_fd(fd) } }) + res.map(|fd| Inotify { + fd: unsafe { OwnedFd::from_raw_fd(fd) }, + }) } /// Adds a new watch on the target file or directory. @@ -157,7 +159,11 @@ impl Inotify { mask: AddWatchFlags, ) -> Result { let res = path.with_nix_path(|cstr| unsafe { - libc::inotify_add_watch(self.fd.as_raw_fd(), cstr.as_ptr(), mask.bits()) + libc::inotify_add_watch( + self.fd.as_raw_fd(), + cstr.as_ptr(), + mask.bits(), + ) })?; Errno::result(res).map(|wd| WatchDescriptor { wd }) @@ -237,7 +243,9 @@ impl Inotify { impl FromRawFd for Inotify { unsafe fn from_raw_fd(fd: RawFd) -> Self { - Inotify { fd: OwnedFd::from_raw_fd(fd) } + Inotify { + fd: OwnedFd::from_raw_fd(fd), + } } } diff --git a/src/sys/ioctl/mod.rs b/src/sys/ioctl/mod.rs index af846f21bb..1eda874966 100644 --- a/src/sys/ioctl/mod.rs +++ b/src/sys/ioctl/mod.rs @@ -238,8 +238,7 @@ pub use self::linux::*; target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "haiku", target_os = "openbsd" @@ -251,8 +250,7 @@ mod bsd; target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "haiku", target_os = "openbsd" diff --git a/src/sys/mman.rs b/src/sys/mman.rs index af986f5ab5..c2299e9648 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -8,7 +8,10 @@ use crate::Result; #[cfg(feature = "fs")] use crate::{fcntl::OFlag, sys::stat::Mode}; use libc::{self, c_int, c_void, off_t, size_t}; -use std::{num::NonZeroUsize, os::unix::io::{AsRawFd, AsFd}}; +use std::{ + num::NonZeroUsize, + os::unix::io::{AsFd, AsRawFd}, +}; libc_bitflags! { /// Desired memory protection of a memory mapping. @@ -169,11 +172,11 @@ libc_bitflags! { #[cfg_attr(docsrs, doc(cfg(all())))] MAP_STACK; /// Pages in this mapping are not retained in the kernel's memory cache. - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg_attr(docsrs, doc(cfg(all())))] MAP_NOCACHE; /// Allows the W/X bit on the page, it's necessary on aarch64 architecture. - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg_attr(docsrs, doc(cfg(all())))] MAP_JIT; /// Allows to use large pages, underlying alignment based on size. @@ -314,19 +317,19 @@ libc_enum! { #[cfg_attr(docsrs, doc(cfg(all())))] MADV_SETMAP, /// Indicates that the application will not need the data in the given range. - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg_attr(docsrs, doc(cfg(all())))] MADV_ZERO_WIRED_PAGES, /// Pages can be reused (by anyone). - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg_attr(docsrs, doc(cfg(all())))] MADV_FREE_REUSABLE, /// Caller wants to reuse those pages. - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg_attr(docsrs, doc(cfg(all())))] MADV_FREE_REUSE, // Darwin doesn't document this flag's behavior. - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg_attr(docsrs, doc(cfg(all())))] #[allow(missing_docs)] MADV_CAN_REUSE, @@ -341,11 +344,11 @@ libc_bitflags! { /// Invalidate all cached data. MS_INVALIDATE; /// Invalidate pages, but leave them mapped. - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg_attr(docsrs, doc(cfg(all())))] MS_KILLPAGES; /// Deactivate pages, but leave them mapped. - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg_attr(docsrs, doc(cfg(all())))] MS_DEACTIVATE; /// Perform an update and wait for it to complete. @@ -605,11 +608,11 @@ pub fn shm_open

( use std::os::unix::io::{FromRawFd, OwnedFd}; let ret = name.with_nix_path(|cstr| { - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] unsafe { libc::shm_open(cstr.as_ptr(), flag.bits(), mode.bits() as libc::c_uint) } - #[cfg(not(any(target_os = "macos", target_os = "ios")))] + #[cfg(not(apple_targets))] unsafe { libc::shm_open(cstr.as_ptr(), flag.bits(), mode.bits() as libc::mode_t) } diff --git a/src/sys/mod.rs b/src/sys/mod.rs index bf047b3dda..f43d8787eb 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -2,9 +2,8 @@ #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", all(target_os = "linux", not(target_env = "uclibc")), - target_os = "macos", + apple_targets, target_os = "netbsd" ))] feature! { @@ -21,8 +20,7 @@ feature! { #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd"))] pub mod event; @@ -36,10 +34,9 @@ feature! { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", target_os = "redox", - target_os = "macos", target_os = "netbsd", target_os = "illumos", target_os = "openbsd" @@ -125,9 +122,8 @@ feature! { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos" ))] feature! { #![feature = "zerocopy"] @@ -159,9 +155,8 @@ feature! { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] feature! { diff --git a/src/sys/prctl.rs b/src/sys/prctl.rs index a48065a66b..42324beab2 100644 --- a/src/sys/prctl.rs +++ b/src/sys/prctl.rs @@ -50,7 +50,9 @@ pub fn get_child_subreaper() -> Result { // prctl writes into this var let mut subreaper: c_int = 0; - let res = unsafe { libc::prctl(libc::PR_GET_CHILD_SUBREAPER, &mut subreaper, 0, 0, 0) }; + let res = unsafe { + libc::prctl(libc::PR_GET_CHILD_SUBREAPER, &mut subreaper, 0, 0, 0) + }; Errno::result(res).map(|_| subreaper != 0) } @@ -78,7 +80,9 @@ pub fn get_keepcaps() -> Result { /// Clear the thread memory corruption kill policy and use the system-wide default pub fn clear_mce_kill() -> Result<()> { - let res = unsafe { libc::prctl(libc::PR_MCE_KILL, libc::PR_MCE_KILL_CLEAR, 0, 0, 0) }; + let res = unsafe { + libc::prctl(libc::PR_MCE_KILL, libc::PR_MCE_KILL_CLEAR, 0, 0, 0) + }; Errno::result(res).map(drop) } @@ -175,14 +179,16 @@ pub fn get_timerslack() -> Result { /// Disable all performance counters attached to the calling process. pub fn task_perf_events_disable() -> Result<()> { - let res = unsafe { libc::prctl(libc::PR_TASK_PERF_EVENTS_DISABLE, 0, 0, 0, 0) }; + let res = + unsafe { libc::prctl(libc::PR_TASK_PERF_EVENTS_DISABLE, 0, 0, 0, 0) }; Errno::result(res).map(drop) } /// Enable all performance counters attached to the calling process. pub fn task_perf_events_enable() -> Result<()> { - let res = unsafe { libc::prctl(libc::PR_TASK_PERF_EVENTS_ENABLE, 0, 0, 0, 0) }; + let res = + unsafe { libc::prctl(libc::PR_TASK_PERF_EVENTS_ENABLE, 0, 0, 0, 0) }; Errno::result(res).map(drop) } diff --git a/src/sys/resource.rs b/src/sys/resource.rs index f42d32e3ca..a040774c58 100644 --- a/src/sys/resource.rs +++ b/src/sys/resource.rs @@ -16,8 +16,7 @@ cfg_if! { target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "android", target_os = "dragonfly", target_os = "aix", @@ -48,8 +47,7 @@ libc_enum! { target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "android", target_os = "dragonfly", target_os = "aix", diff --git a/src/sys/sendfile.rs b/src/sys/sendfile.rs index da979d337b..7e4ee74210 100644 --- a/src/sys/sendfile.rs +++ b/src/sys/sendfile.rs @@ -80,8 +80,7 @@ pub fn sendfile64( cfg_if! { if #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos"))] { + apple_targets,))] { use std::io::IoSlice; #[derive(Clone, Debug)] @@ -244,7 +243,7 @@ cfg_if! { }; (Errno::result(return_code).and(Ok(())), bytes_sent) } - } else if #[cfg(any(target_os = "ios", target_os = "macos"))] { + } else if #[cfg(apple_targets)] { /// Read bytes from `in_fd` starting at `offset` and write up to `count` bytes to /// `out_sock`. /// diff --git a/src/sys/signalfd.rs b/src/sys/signalfd.rs index 36516074a6..aefc89bc73 100644 --- a/src/sys/signalfd.rs +++ b/src/sys/signalfd.rs @@ -21,7 +21,7 @@ use crate::Result; pub use libc::signalfd_siginfo as siginfo; use std::mem; -use std::os::unix::io::{AsRawFd, RawFd, FromRawFd, OwnedFd, AsFd, BorrowedFd}; +use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd}; libc_bitflags! { pub struct SfdFlags: libc::c_int { @@ -45,18 +45,23 @@ pub const SIGNALFD_SIGINFO_SIZE: usize = mem::size_of::(); /// /// See [the signalfd man page for more information](https://man7.org/linux/man-pages/man2/signalfd.2.html) #[deprecated(since = "0.27.0", note = "Use SignalFd instead")] -pub fn signalfd(fd: Option, mask: &SigSet, flags: SfdFlags) -> Result { +pub fn signalfd( + fd: Option, + mask: &SigSet, + flags: SfdFlags, +) -> Result { _signalfd(fd, mask, flags) } -fn _signalfd(fd: Option, mask: &SigSet, flags: SfdFlags) -> Result { - let raw_fd = fd.map_or(-1, |x|x.as_fd().as_raw_fd()); +fn _signalfd( + fd: Option, + mask: &SigSet, + flags: SfdFlags, +) -> Result { + let raw_fd = fd.map_or(-1, |x| x.as_fd().as_raw_fd()); unsafe { - Errno::result(libc::signalfd( - raw_fd, - mask.as_ref(), - flags.bits(), - )).map(|raw_fd|FromRawFd::from_raw_fd(raw_fd)) + Errno::result(libc::signalfd(raw_fd, mask.as_ref(), flags.bits())) + .map(|raw_fd| FromRawFd::from_raw_fd(raw_fd)) } } @@ -123,11 +128,8 @@ impl SignalFd { fn update(&self, mask: &SigSet, flags: SfdFlags) -> Result<()> { let raw_fd = self.0.as_raw_fd(); unsafe { - Errno::result(libc::signalfd( - raw_fd, - mask.as_ref(), - flags.bits(), - )).map(drop) + Errno::result(libc::signalfd(raw_fd, mask.as_ref(), flags.bits())) + .map(drop) } } } diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 097a9d786a..f973bfaedb 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -2,9 +2,8 @@ target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "illumos", target_os = "netbsd", target_os = "openbsd", @@ -14,7 +13,11 @@ ))] #[cfg(feature = "net")] pub use self::datalink::LinkAddr; -#[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] +#[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "macos" +))] pub use self::vsock::VsockAddr; use super::sa_family_t; use crate::errno::Errno; @@ -22,10 +25,7 @@ use crate::errno::Errno; use crate::sys::socket::addr::alg::AlgAddr; #[cfg(any(target_os = "android", target_os = "linux"))] use crate::sys::socket::addr::netlink::NetlinkAddr; -#[cfg(all( - feature = "ioctl", - any(target_os = "ios", target_os = "macos") -))] +#[cfg(all(feature = "ioctl", apple_targets))] use crate::sys::socket::addr::sys_control::SysControlAddr; use crate::{NixPath, Result}; use cfg_if::cfg_if; @@ -33,16 +33,16 @@ use memoffset::offset_of; use std::convert::TryInto; use std::ffi::OsStr; use std::hash::{Hash, Hasher}; +use std::net::{Ipv4Addr, Ipv6Addr}; use std::os::unix::ffi::OsStrExt; use std::path::Path; use std::{fmt, mem, net, ptr, slice}; -use std::net::{Ipv4Addr,Ipv6Addr}; /// Convert a std::net::Ipv4Addr into the libc form. #[cfg(feature = "net")] pub(crate) const fn ipv4addr_to_libc(addr: net::Ipv4Addr) -> libc::in_addr { libc::in_addr { - s_addr: u32::from_ne_bytes(addr.octets()) + s_addr: u32::from_ne_bytes(addr.octets()), } } @@ -50,7 +50,7 @@ pub(crate) const fn ipv4addr_to_libc(addr: net::Ipv4Addr) -> libc::in_addr { #[cfg(feature = "net")] pub(crate) const fn ipv6addr_to_libc(addr: &net::Ipv6Addr) -> libc::in6_addr { libc::in6_addr { - s6_addr: addr.octets() + s6_addr: addr.octets(), } } @@ -93,7 +93,7 @@ pub enum AddressFamily { #[cfg_attr(docsrs, doc(cfg(all())))] Packet = libc::AF_PACKET, /// KEXT Controls and Notifications - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg_attr(docsrs, doc(cfg(all())))] System = libc::AF_SYSTEM, /// Amateur radio AX.25 protocol @@ -205,8 +205,7 @@ pub enum AddressFamily { #[cfg(not(any( target_os = "aix", target_os = "illumos", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "solaris", target_os = "redox", )))] @@ -253,15 +252,18 @@ pub enum AddressFamily { #[cfg_attr(docsrs, doc(cfg(all())))] Nfc = libc::AF_NFC, /// VMWare VSockets protocol for hypervisor-guest interaction. - #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] + #[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "macos" + ))] #[cfg_attr(docsrs, doc(cfg(all())))] Vsock = libc::AF_VSOCK, /// ARPANet IMP addresses #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -271,8 +273,7 @@ pub enum AddressFamily { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -282,28 +283,21 @@ pub enum AddressFamily { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] Chaos = libc::AF_CHAOS, /// Novell and Xerox protocol - #[cfg(any( - target_os = "ios", - target_os = "macos", - target_os = "netbsd", - target_os = "openbsd" - ))] + #[cfg(any(apple_targets, target_os = "netbsd", target_os = "openbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] Ns = libc::AF_NS, #[allow(missing_docs)] // Not documented anywhere that I can find #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -313,8 +307,7 @@ pub enum AddressFamily { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -324,8 +317,7 @@ pub enum AddressFamily { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -335,8 +327,7 @@ pub enum AddressFamily { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -346,8 +337,7 @@ pub enum AddressFamily { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -357,8 +347,7 @@ pub enum AddressFamily { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -368,8 +357,7 @@ pub enum AddressFamily { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "illumos", target_os = "netbsd", target_os = "openbsd" @@ -380,8 +368,7 @@ pub enum AddressFamily { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -391,8 +378,7 @@ pub enum AddressFamily { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -402,8 +388,7 @@ pub enum AddressFamily { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -441,14 +426,17 @@ impl AddressFamily { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "illumos", target_os = "openbsd" ))] libc::AF_LINK => Some(AddressFamily::Link), - #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] + #[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "macos" + ))] libc::AF_VSOCK => Some(AddressFamily::Vsock), _ => None, } @@ -489,7 +477,7 @@ enum UnixAddrKind<'a> { } impl<'a> UnixAddrKind<'a> { /// Safety: sun & sun_len must be valid - #[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms + #[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms unsafe fn get(sun: &'a libc::sockaddr_un, sun_len: u8) -> Self { assert!(sun_len as usize >= offset_of!(libc::sockaddr_un, sun_path)); let path_len = @@ -526,7 +514,7 @@ impl<'a> UnixAddrKind<'a> { impl UnixAddr { /// Create a new sockaddr_un representing a filesystem path. - #[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms + #[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms pub fn new(path: &P) -> Result { path.with_nix_path(|cstr| unsafe { let mut ret = libc::sockaddr_un { @@ -548,8 +536,7 @@ impl UnixAddr { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -574,7 +561,7 @@ impl UnixAddr { /// processes to communicate with processes having a different filesystem view. #[cfg(any(target_os = "android", target_os = "linux"))] #[cfg_attr(docsrs, doc(cfg(all())))] - #[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms + #[allow(clippy::unnecessary_cast)] // Not unnecessary on all platforms pub fn new_abstract(path: &[u8]) -> Result { unsafe { let mut ret = libc::sockaddr_un { @@ -771,7 +758,10 @@ impl SockaddrLike for UnixAddr { mem::size_of::() as libc::socklen_t } - unsafe fn set_length(&mut self, new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { + unsafe fn set_length( + &mut self, + new_length: usize, + ) -> std::result::Result<(), SocketAddressLengthNotDynamic> { // `new_length` is only used on some platforms, so it must be provided even when not used #![allow(unused_variables)] cfg_if! { @@ -897,8 +887,7 @@ pub trait SockaddrLike: private::SockaddrLikePriv { cfg_if! { if #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd"))] { /// Return the length of valid data in the sockaddr structure. @@ -947,7 +936,10 @@ pub trait SockaddrLike: private::SockaddrLikePriv { /// `new_length` must be a valid length for this type of address. Specifically, reads of that /// length from `self` must be valid. #[doc(hidden)] - unsafe fn set_length(&mut self, _new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { + unsafe fn set_length( + &mut self, + _new_length: usize, + ) -> std::result::Result<(), SocketAddressLengthNotDynamic> { Err(SocketAddressLengthNotDynamic) } } @@ -1019,8 +1011,7 @@ impl SockaddrIn { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "aix", target_os = "haiku", @@ -1099,8 +1090,7 @@ impl From for SockaddrIn { target_os = "freebsd", target_os = "haiku", target_os = "hermit", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -1148,14 +1138,15 @@ impl SockaddrIn6 { /// Returns the IP address associated with this socket address. pub const fn ip(&self) -> net::Ipv6Addr { let bytes = self.0.sin6_addr.s6_addr; - let (a, b, c, d, e, f, g, h) = (((bytes[0] as u16) << 8) | bytes[1] as u16, + let (a, b, c, d, e, f, g, h) = ( + ((bytes[0] as u16) << 8) | bytes[1] as u16, ((bytes[2] as u16) << 8) | bytes[3] as u16, ((bytes[4] as u16) << 8) | bytes[5] as u16, ((bytes[6] as u16) << 8) | bytes[7] as u16, ((bytes[8] as u16) << 8) | bytes[9] as u16, ((bytes[10] as u16) << 8) | bytes[11] as u16, ((bytes[12] as u16) << 8) | bytes[13] as u16, - ((bytes[14] as u16) << 8) | bytes[15] as u16 + ((bytes[14] as u16) << 8) | bytes[15] as u16, ); Ipv6Addr::new(a, b, c, d, e, f, g, h) } @@ -1227,8 +1218,7 @@ impl From for SockaddrIn6 { target_os = "freebsd", target_os = "haiku", target_os = "hermit", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -1294,10 +1284,7 @@ pub union SockaddrStorage { dl: LinkAddr, #[cfg(any(target_os = "android", target_os = "linux"))] nl: NetlinkAddr, - #[cfg(all( - feature = "ioctl", - any(target_os = "ios", target_os = "macos") - ))] + #[cfg(all(feature = "ioctl", apple_targets))] #[cfg_attr(docsrs, doc(cfg(feature = "ioctl")))] sctl: SysControlAddr, #[cfg(feature = "net")] @@ -1306,7 +1293,11 @@ pub union SockaddrStorage { sin6: SockaddrIn6, ss: libc::sockaddr_storage, su: UnixAddr, - #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos" ))] + #[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "macos" + ))] #[cfg_attr(docsrs, doc(cfg(all())))] vsock: VsockAddr, } @@ -1367,8 +1358,7 @@ impl SockaddrLike for SockaddrStorage { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "illumos", target_os = "netbsd", target_os = "haiku", @@ -1391,14 +1381,15 @@ impl SockaddrLike for SockaddrStorage { libc::AF_PACKET => { LinkAddr::from_raw(addr, l).map(|dl| Self { dl }) } - #[cfg(all( - feature = "ioctl", - any(target_os = "ios", target_os = "macos") - ))] + #[cfg(all(feature = "ioctl", apple_targets))] libc::AF_SYSTEM => { SysControlAddr::from_raw(addr, l).map(|sctl| Self { sctl }) } - #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos" ))] + #[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "macos" + ))] libc::AF_VSOCK => { VsockAddr::from_raw(addr, l).map(|vsock| Self { vsock }) } @@ -1422,11 +1413,12 @@ impl SockaddrLike for SockaddrStorage { } } - unsafe fn set_length(&mut self, new_length: usize) -> std::result::Result<(), SocketAddressLengthNotDynamic> { + unsafe fn set_length( + &mut self, + new_length: usize, + ) -> std::result::Result<(), SocketAddressLengthNotDynamic> { match self.as_unix_addr_mut() { - Some(addr) => { - addr.set_length(new_length) - }, + Some(addr) => addr.set_length(new_length), None => Err(SocketAddressLengthNotDynamic), } } @@ -1544,8 +1536,7 @@ impl SockaddrStorage { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "illumos", target_os = "netbsd", target_os = "openbsd" @@ -1569,12 +1560,16 @@ impl SockaddrStorage { accessors! {as_netlink_addr, as_netlink_addr_mut, NetlinkAddr, AddressFamily::Netlink, libc::sockaddr_nl, nl} - #[cfg(all(feature = "ioctl", any(target_os = "ios", target_os = "macos")))] + #[cfg(all(feature = "ioctl", apple_targets))] #[cfg_attr(docsrs, doc(cfg(feature = "ioctl")))] accessors! {as_sys_control_addr, as_sys_control_addr_mut, SysControlAddr, AddressFamily::System, libc::sockaddr_ctl, sctl} - #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] + #[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "macos" + ))] #[cfg_attr(docsrs, doc(cfg(all())))] accessors! {as_vsock_addr, as_vsock_addr_mut, VsockAddr, AddressFamily::Vsock, libc::sockaddr_vm, vsock} @@ -1603,8 +1598,7 @@ impl fmt::Display for SockaddrStorage { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "illumos", target_os = "netbsd", target_os = "openbsd" @@ -1620,11 +1614,15 @@ impl fmt::Display for SockaddrStorage { ))] #[cfg(feature = "net")] libc::AF_PACKET => self.dl.fmt(f), - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg(feature = "ioctl")] libc::AF_SYSTEM => self.sctl.fmt(f), libc::AF_UNIX => self.su.fmt(f), - #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] + #[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "macos" + ))] libc::AF_VSOCK => self.vsock.fmt(f), _ => "

".fmt(f), } @@ -1677,8 +1675,7 @@ impl Hash for SockaddrStorage { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "illumos", target_os = "netbsd", target_os = "openbsd" @@ -1694,11 +1691,15 @@ impl Hash for SockaddrStorage { ))] #[cfg(feature = "net")] libc::AF_PACKET => self.dl.hash(s), - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg(feature = "ioctl")] libc::AF_SYSTEM => self.sctl.hash(s), libc::AF_UNIX => self.su.hash(s), - #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] + #[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "macos" + ))] libc::AF_VSOCK => self.vsock.hash(s), _ => self.ss.hash(s), } @@ -1719,8 +1720,7 @@ impl PartialEq for SockaddrStorage { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "illumos", target_os = "netbsd", target_os = "openbsd" @@ -1736,11 +1736,15 @@ impl PartialEq for SockaddrStorage { ))] #[cfg(feature = "net")] (libc::AF_PACKET, libc::AF_PACKET) => self.dl == other.dl, - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg(feature = "ioctl")] (libc::AF_SYSTEM, libc::AF_SYSTEM) => self.sctl == other.sctl, (libc::AF_UNIX, libc::AF_UNIX) => self.su == other.su, - #[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))] + #[cfg(any( + target_os = "android", + target_os = "linux", + target_os = "macos" + ))] (libc::AF_VSOCK, libc::AF_VSOCK) => self.vsock == other.vsock, _ => false, } @@ -1931,16 +1935,12 @@ pub mod alg { /// Return the socket's cipher type, for example `hash` or `aead`. pub fn alg_type(&self) -> &CStr { - unsafe { - CStr::from_ptr(self.0.salg_type.as_ptr().cast()) - } + unsafe { CStr::from_ptr(self.0.salg_type.as_ptr().cast()) } } /// Return the socket's cipher name, for example `sha1`. pub fn alg_name(&self) -> &CStr { - unsafe { - CStr::from_ptr(self.0.salg_name.as_ptr().cast()) - } + unsafe { CStr::from_ptr(self.0.salg_name.as_ptr().cast()) } } } @@ -1964,7 +1964,7 @@ pub mod alg { feature! { #![feature = "ioctl"] -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple_targets)] pub mod sys_control { use crate::sys::socket::addr::AddressFamily; use libc::{self, c_uchar}; @@ -2168,8 +2168,7 @@ mod datalink { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "illumos", target_os = "netbsd", target_os = "haiku", @@ -2344,8 +2343,17 @@ pub mod vsock { #[cfg(target_os = "macos")] fn eq(&self, other: &Self) -> bool { let (inner, other) = (self.0, other.0); - (inner.svm_family, inner.svm_cid, inner.svm_port, inner.svm_len) - == (other.svm_family, other.svm_cid, other.svm_port, inner.svm_len) + ( + inner.svm_family, + inner.svm_cid, + inner.svm_port, + inner.svm_len, + ) == ( + other.svm_family, + other.svm_cid, + other.svm_port, + inner.svm_len, + ) } } @@ -2360,7 +2368,13 @@ pub mod vsock { #[cfg(target_os = "macos")] fn hash(&self, s: &mut H) { let inner = self.0; - (inner.svm_family, inner.svm_cid, inner.svm_port, inner.svm_len).hash(s); + ( + inner.svm_family, + inner.svm_cid, + inner.svm_port, + inner.svm_len, + ) + .hash(s); } } @@ -2378,7 +2392,7 @@ pub mod vsock { #[cfg(target_os = "macos")] { - addr.svm_len = std::mem::size_of::() as u8; + addr.svm_len = std::mem::size_of::() as u8; } VsockAddr(addr) } @@ -2436,11 +2450,7 @@ mod tests { mod link { #![allow(clippy::cast_ptr_alignment)] - #[cfg(any( - target_os = "ios", - target_os = "macos", - target_os = "illumos" - ))] + #[cfg(any(apple_targets, target_os = "illumos"))] use super::super::super::socklen_t; use super::*; @@ -2448,8 +2458,7 @@ mod tests { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -2498,7 +2507,7 @@ mod tests { } } - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[test] fn macos_loopback() { let bytes = @@ -2516,7 +2525,7 @@ mod tests { } } - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[test] fn macos_tap() { let bytes = [ @@ -2565,8 +2574,7 @@ mod tests { target_os = "aix", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "illumos", target_os = "openbsd", @@ -2634,7 +2642,6 @@ mod tests { let s = "[1234:5678:90ab:cdef::1111:2222]:8080"; let ip = SockaddrIn6::from_str(s).unwrap().ip(); assert_eq!("1234:5678:90ab:cdef::1111:2222", format!("{ip}")); - } #[test] diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index b34c4c3fdb..6f8c6f3eb2 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -59,7 +59,7 @@ pub use self::addr::{SockaddrIn, SockaddrIn6}; pub use crate::sys::socket::addr::alg::AlgAddr; #[cfg(any(target_os = "android", target_os = "linux"))] pub use crate::sys::socket::addr::netlink::NetlinkAddr; -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple_targets)] #[cfg(feature = "ioctl")] pub use crate::sys::socket::addr::sys_control::SysControlAddr; #[cfg(any( @@ -138,7 +138,7 @@ pub enum SockProtocol { Raw = libc::IPPROTO_RAW, /// Allows applications to configure and control a KEXT /// ([ref](https://developer.apple.com/library/content/documentation/Darwin/Conceptual/NKEConceptual/control/control.html)) - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg_attr(docsrs, doc(cfg(all())))] KextControl = libc::SYSPROTO_CONTROL, /// Receives routing and link updates and may be used to modify the routing tables (both IPv4 and IPv6), IP addresses, link @@ -253,10 +253,10 @@ impl SockProtocol { /// Allows applications and other KEXTs to be notified when certain kernel events occur /// ([ref](https://developer.apple.com/library/content/documentation/Darwin/Conceptual/NKEConceptual/control/control.html)) - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg_attr(docsrs, doc(cfg(all())))] #[allow(non_upper_case_globals)] - pub const KextEvent: SockProtocol = SockProtocol::Icmp; // Matches libc::SYSPROTO_EVENT + pub const KextEvent: SockProtocol = SockProtocol::Icmp; // Matches libc::SYSPROTO_EVENT } #[cfg(any(target_os = "android", target_os = "linux"))] libc_bitflags! { @@ -518,8 +518,7 @@ cfg_if! { if #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "macos", - target_os = "ios" + apple_targets ))] { /// Return type of [`LocalPeerCred`](crate::sys::socket::sockopt::LocalPeerCred) #[repr(transparent)] @@ -782,9 +781,8 @@ pub enum ControlMessageOwned { ScmTimestampns(TimeSpec), #[cfg(any( target_os = "android", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", ))] #[cfg(feature = "net")] @@ -794,9 +792,8 @@ pub enum ControlMessageOwned { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd", target_os = "netbsd", ))] @@ -805,8 +802,7 @@ pub enum ControlMessageOwned { Ipv6PacketInfo(libc::in6_pktinfo), #[cfg(any( target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd", ))] @@ -815,8 +811,7 @@ pub enum ControlMessageOwned { Ipv4RecvIf(libc::sockaddr_dl), #[cfg(any( target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd", ))] @@ -947,9 +942,8 @@ impl ControlMessageOwned { #[cfg(any( target_os = "android", target_os = "freebsd", - target_os = "ios", - target_os = "linux", - target_os = "macos" + apple_targets, + target_os = "linux" ))] #[cfg(feature = "net")] (libc::IPPROTO_IPV6, libc::IPV6_PKTINFO) => { @@ -958,9 +952,8 @@ impl ControlMessageOwned { } #[cfg(any( target_os = "android", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", ))] #[cfg(feature = "net")] @@ -970,8 +963,7 @@ impl ControlMessageOwned { } #[cfg(any( target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd", ))] @@ -982,8 +974,7 @@ impl ControlMessageOwned { }, #[cfg(any( target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd", ))] @@ -1156,10 +1147,9 @@ 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 = "macos", target_os = "netbsd", target_os = "android", - target_os = "ios",))] + apple_targets))] #[cfg(feature = "net")] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] Ipv4PacketInfo(&'a libc::in_pktinfo), @@ -1169,11 +1159,10 @@ pub enum ControlMessage<'a> { /// For further information, please refer to the /// [`ipv6(7)`](https://man7.org/linux/man-pages/man7/ipv6.7.html) man page. #[cfg(any(target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "freebsd", target_os = "android", - target_os = "ios",))] + apple_targets))] #[cfg(feature = "net")] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] Ipv6PacketInfo(&'a libc::in6_pktinfo), @@ -1197,10 +1186,9 @@ pub enum ControlMessage<'a> { /// with sendmsg have a hop limit of 1 and will not leave the local network. /// For further information, please refer to the /// [`ipv6(7)`](https://man7.org/linux/man-pages/man7/ipv6.7.html) man page. - #[cfg(any(target_os = "linux", target_os = "macos", - target_os = "freebsd", target_os = "dragonfly", - target_os = "android", target_os = "ios", - target_os = "haiku"))] + #[cfg(any(target_os = "linux", target_os = "freebsd", + target_os = "dragonfly", target_os = "android", + apple_targets, target_os = "haiku"))] #[cfg(feature = "net")] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] Ipv6HopLimit(&'a libc::c_int), @@ -1304,24 +1292,22 @@ impl<'a> ControlMessage<'a> { ControlMessage::UdpGsoSegments(gso_size) => { gso_size as *const _ as *const u8 }, - #[cfg(any(target_os = "linux", target_os = "macos", - target_os = "netbsd", target_os = "android", - target_os = "ios",))] + #[cfg(any(target_os = "linux", target_os = "netbsd", + target_os = "android", apple_targets))] #[cfg(feature = "net")] ControlMessage::Ipv4PacketInfo(info) => info as *const _ as *const u8, - #[cfg(any(target_os = "linux", target_os = "macos", - target_os = "netbsd", target_os = "freebsd", - target_os = "android", target_os = "ios",))] + #[cfg(any(target_os = "linux", target_os = "netbsd", + target_os = "freebsd", target_os = "android", + apple_targets))] #[cfg(feature = "net")] ControlMessage::Ipv6PacketInfo(info) => info as *const _ as *const u8, #[cfg(any(target_os = "netbsd", target_os = "freebsd", target_os = "openbsd", target_os = "dragonfly"))] #[cfg(feature = "net")] ControlMessage::Ipv4SendSrcAddr(addr) => addr as *const _ as *const u8, - #[cfg(any(target_os = "linux", target_os = "macos", - target_os = "freebsd", target_os = "dragonfly", - target_os = "android", target_os = "ios", - target_os = "haiku"))] + #[cfg(any(target_os = "linux", target_os = "freebsd", + target_os = "dragonfly", target_os = "android", + apple_targets, target_os = "haiku"))] #[cfg(feature = "net")] ControlMessage::Ipv6HopLimit(limit) => limit as *const _ as *const u8, #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] @@ -1373,24 +1359,22 @@ impl<'a> ControlMessage<'a> { ControlMessage::UdpGsoSegments(gso_size) => { mem::size_of_val(gso_size) }, - #[cfg(any(target_os = "linux", target_os = "macos", - target_os = "netbsd", target_os = "android", - target_os = "ios",))] + #[cfg(any(target_os = "linux", target_os = "netbsd", + target_os = "android", apple_targets))] #[cfg(feature = "net")] ControlMessage::Ipv4PacketInfo(info) => mem::size_of_val(info), - #[cfg(any(target_os = "linux", target_os = "macos", - target_os = "netbsd", target_os = "freebsd", - target_os = "android", target_os = "ios",))] + #[cfg(any(target_os = "linux", target_os = "netbsd", + target_os = "freebsd", target_os = "android", + apple_targets))] #[cfg(feature = "net")] ControlMessage::Ipv6PacketInfo(info) => mem::size_of_val(info), #[cfg(any(target_os = "netbsd", target_os = "freebsd", target_os = "openbsd", target_os = "dragonfly"))] #[cfg(feature = "net")] ControlMessage::Ipv4SendSrcAddr(addr) => mem::size_of_val(addr), - #[cfg(any(target_os = "linux", target_os = "macos", - target_os = "freebsd", target_os = "dragonfly", - target_os = "android", target_os = "ios", - target_os = "haiku"))] + #[cfg(any(target_os = "linux", target_os = "freebsd", + target_os = "dragonfly", target_os = "android", + apple_targets, target_os = "haiku"))] #[cfg(feature = "net")] ControlMessage::Ipv6HopLimit(limit) => { mem::size_of_val(limit) @@ -1420,24 +1404,22 @@ impl<'a> ControlMessage<'a> { #[cfg(target_os = "linux")] #[cfg(feature = "net")] ControlMessage::UdpGsoSegments(_) => libc::SOL_UDP, - #[cfg(any(target_os = "linux", target_os = "macos", - target_os = "netbsd", target_os = "android", - target_os = "ios",))] + #[cfg(any(target_os = "linux", target_os = "netbsd", + target_os = "android", apple_targets,))] #[cfg(feature = "net")] ControlMessage::Ipv4PacketInfo(_) => libc::IPPROTO_IP, - #[cfg(any(target_os = "linux", target_os = "macos", - target_os = "netbsd", target_os = "freebsd", - target_os = "android", target_os = "ios",))] + #[cfg(any(target_os = "linux", target_os = "netbsd", + target_os = "freebsd", target_os = "android", + apple_targets))] #[cfg(feature = "net")] ControlMessage::Ipv6PacketInfo(_) => libc::IPPROTO_IPV6, #[cfg(any(target_os = "netbsd", target_os = "freebsd", target_os = "openbsd", target_os = "dragonfly"))] #[cfg(feature = "net")] ControlMessage::Ipv4SendSrcAddr(_) => libc::IPPROTO_IP, - #[cfg(any(target_os = "linux", target_os = "macos", - target_os = "freebsd", target_os = "dragonfly", - target_os = "android", target_os = "ios", - target_os = "haiku"))] + #[cfg(any(target_os = "linux", target_os = "freebsd", + target_os = "dragonfly", target_os = "android", + apple_targets, target_os = "haiku"))] #[cfg(feature = "net")] ControlMessage::Ipv6HopLimit(_) => libc::IPPROTO_IPV6, #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] @@ -1472,24 +1454,22 @@ impl<'a> ControlMessage<'a> { ControlMessage::UdpGsoSegments(_) => { libc::UDP_SEGMENT }, - #[cfg(any(target_os = "linux", target_os = "macos", - target_os = "netbsd", target_os = "android", - target_os = "ios",))] + #[cfg(any(target_os = "linux", target_os = "netbsd", + target_os = "android", apple_targets))] #[cfg(feature = "net")] ControlMessage::Ipv4PacketInfo(_) => libc::IP_PKTINFO, - #[cfg(any(target_os = "linux", target_os = "macos", - target_os = "netbsd", target_os = "freebsd", - target_os = "android", target_os = "ios",))] + #[cfg(any(target_os = "linux", target_os = "netbsd", + target_os = "freebsd", target_os = "android", + apple_targets))] #[cfg(feature = "net")] ControlMessage::Ipv6PacketInfo(_) => libc::IPV6_PKTINFO, #[cfg(any(target_os = "netbsd", target_os = "freebsd", target_os = "openbsd", target_os = "dragonfly"))] #[cfg(feature = "net")] ControlMessage::Ipv4SendSrcAddr(_) => libc::IP_SENDSRCADDR, - #[cfg(any(target_os = "linux", target_os = "macos", - target_os = "freebsd", target_os = "dragonfly", - target_os = "android", target_os = "ios", - target_os = "haiku"))] + #[cfg(any(target_os = "linux", target_os = "freebsd", + target_os = "dragonfly", target_os = "android", + apple_targets, target_os = "haiku"))] #[cfg(feature = "net")] ControlMessage::Ipv6HopLimit(_) => libc::IPV6_HOPLIMIT, #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] @@ -2372,12 +2352,7 @@ pub fn sendto( /// [Further reading](https://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html) pub fn send(fd: RawFd, buf: &[u8], flags: MsgFlags) -> Result { let ret = unsafe { - libc::send( - fd, - buf.as_ptr().cast(), - buf.len() as size_t, - flags.bits(), - ) + libc::send(fd, buf.as_ptr().cast(), buf.len() as size_t, flags.bits()) }; Errno::result(ret).map(|r| r as usize) @@ -2444,8 +2419,7 @@ pub fn getpeername(fd: RawFd) -> Result { let mut addr = mem::MaybeUninit::::uninit(); let mut len = T::size(); - let ret = - libc::getpeername(fd, addr.as_mut_ptr().cast(), &mut len); + let ret = libc::getpeername(fd, addr.as_mut_ptr().cast(), &mut len); Errno::result(ret)?; @@ -2461,8 +2435,7 @@ pub fn getsockname(fd: RawFd) -> Result { let mut addr = mem::MaybeUninit::::uninit(); let mut len = T::size(); - let ret = - libc::getsockname(fd, addr.as_mut_ptr().cast(), &mut len); + let ret = libc::getsockname(fd, addr.as_mut_ptr().cast(), &mut len); Errno::result(ret)?; diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index b46f208216..07a0ac4ed5 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -332,8 +332,7 @@ cfg_if! { } else if #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd", target_os = "solaris"))] { @@ -477,12 +476,7 @@ sockopt_impl!( libc::SO_KEEPALIVE, bool ); -#[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "macos", - target_os = "ios" -))] +#[cfg(any(target_os = "dragonfly", target_os = "freebsd", apple_targets))] sockopt_impl!( /// Get the credentials of the peer process of a connected unix domain /// socket. @@ -492,7 +486,7 @@ sockopt_impl!( libc::LOCAL_PEERCRED, super::XuCred ); -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(apple_targets)] sockopt_impl!( /// Get the PID of the peer process of a connected unix domain socket. LocalPeerPid, @@ -510,7 +504,7 @@ sockopt_impl!( libc::SO_PEERCRED, super::UnixCredentials ); -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple_targets)] #[cfg(feature = "net")] sockopt_impl!( #[cfg_attr(docsrs, doc(cfg(feature = "net")))] @@ -838,9 +832,8 @@ sockopt_impl!( ); #[cfg(any( target_os = "android", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", ))] #[cfg(feature = "net")] @@ -857,9 +850,8 @@ sockopt_impl!( #[cfg(any( target_os = "android", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd", ))] @@ -876,8 +868,7 @@ sockopt_impl!( ); #[cfg(any( target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd", ))] @@ -894,8 +885,7 @@ sockopt_impl!( ); #[cfg(any( target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd", ))] @@ -1035,7 +1025,7 @@ sockopt_impl!( libc::IPV6_ORIGDSTADDR, bool ); -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple_targets)] sockopt_impl!( /// Set "don't fragment packet" flag on the IP packet. IpDontFrag, @@ -1044,12 +1034,7 @@ sockopt_impl!( libc::IP_DONTFRAG, bool ); -#[cfg(any( - target_os = "android", - target_os = "ios", - target_os = "linux", - target_os = "macos", -))] +#[cfg(any(target_os = "android", apple_targets, target_os = "linux",))] sockopt_impl!( /// Set "don't fragment packet" flag on the IPv6 packet. Ipv6DontFrag, diff --git a/src/sys/stat.rs b/src/sys/stat.rs index 162e97042a..cc15495baf 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -1,4 +1,4 @@ -#[cfg(any(target_os = "macos", target_os = "ios", target_os = "openbsd"))] +#[cfg(any(apple_targets, target_os = "openbsd"))] pub use libc::c_uint; #[cfg(any( target_os = "netbsd", @@ -65,7 +65,7 @@ libc_bitflags! { } } -#[cfg(any(target_os = "macos", target_os = "ios", target_os = "openbsd"))] +#[cfg(any(apple_targets, target_os = "openbsd"))] pub type type_of_file_flag = c_uint; #[cfg(any( target_os = "netbsd", @@ -79,8 +79,7 @@ pub type type_of_file_flag = c_ulong; target_os = "netbsd", target_os = "freebsd", target_os = "dragonfly", - target_os = "macos", - target_os = "ios" + apple_targets ))] libc_bitflags! { /// File flags. @@ -121,14 +120,13 @@ libc_bitflags! { #[cfg(any(target_os = "dragonfly"))] UF_CACHE; /// File is compressed at the file system level. - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] UF_COMPRESSED; /// The file may be hidden from directory listings at the application's /// discretion. #[cfg(any( target_os = "freebsd", - target_os = "macos", - target_os = "ios", + apple_targets, ))] UF_HIDDEN; /// The file may not be changed. @@ -162,7 +160,7 @@ libc_bitflags! { #[cfg(any(target_os = "freebsd"))] UF_SYSTEM; /// File renames and deletes are tracked. - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] UF_TRACKED; #[cfg(any(target_os = "dragonfly"))] UF_XLINK; @@ -184,12 +182,7 @@ pub fn mknod( } /// Create a special or ordinary file, relative to a given directory. -#[cfg(not(any( - target_os = "ios", - target_os = "macos", - target_os = "redox", - target_os = "haiku" -)))] +#[cfg(not(any(apple_targets, target_os = "redox", target_os = "haiku")))] #[cfg_attr(docsrs, doc(cfg(all())))] pub fn mknodat( dirfd: Option, @@ -385,8 +378,7 @@ pub fn utimes( #[cfg(any( target_os = "linux", target_os = "haiku", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "freebsd", target_os = "netbsd" ))] diff --git a/src/sys/statfs.rs b/src/sys/statfs.rs index 5111df2e6e..52e2a6b43b 100644 --- a/src/sys/statfs.rs +++ b/src/sys/statfs.rs @@ -302,8 +302,7 @@ impl Statfs { #[cfg(not(any( target_os = "openbsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos" + apple_targets, )))] #[cfg_attr(docsrs, doc(cfg(all())))] pub fn filesystem_type(&self) -> FsType { @@ -319,7 +318,7 @@ impl Statfs { } /// Optimal transfer block size - #[cfg(any(target_os = "ios", target_os = "macos"))] + #[cfg(apple_targets)] #[cfg_attr(docsrs, doc(cfg(all())))] pub fn optimal_transfer_size(&self) -> i32 { self.0.f_iosize @@ -385,7 +384,7 @@ impl Statfs { } /// Size of a block - #[cfg(any(target_os = "ios", target_os = "macos", target_os = "openbsd"))] + #[cfg(any(apple_targets, target_os = "openbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] pub fn block_size(&self) -> u32 { self.0.f_bsize @@ -528,8 +527,7 @@ impl Statfs { /// Total data blocks in filesystem #[cfg(any( - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "android", target_os = "freebsd", target_os = "fuchsia", @@ -557,8 +555,7 @@ impl Statfs { /// Free blocks in filesystem #[cfg(any( - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "android", target_os = "freebsd", target_os = "fuchsia", @@ -586,8 +583,7 @@ impl Statfs { /// Free blocks available to unprivileged user #[cfg(any( - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "android", target_os = "fuchsia", target_os = "linux", @@ -620,8 +616,7 @@ impl Statfs { /// Total file nodes in filesystem #[cfg(any( - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "android", target_os = "freebsd", target_os = "fuchsia", @@ -649,8 +644,7 @@ impl Statfs { /// Free file nodes in filesystem #[cfg(any( - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "android", target_os = "fuchsia", target_os = "openbsd", diff --git a/src/sys/termios.rs b/src/sys/termios.rs index ecaa3eaf8f..85d27bcd52 100644 --- a/src/sys/termios.rs +++ b/src/sys/termios.rs @@ -89,8 +89,7 @@ any( target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ), @@ -100,8 +99,7 @@ not(any( target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" )), @@ -122,8 +120,7 @@ any( target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ), @@ -133,8 +130,7 @@ not(any( target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" )), @@ -155,8 +151,7 @@ any( target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ), @@ -166,8 +161,7 @@ not(any( target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" )), @@ -189,8 +183,7 @@ any( target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ), @@ -200,8 +193,7 @@ not(any( target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" )), @@ -356,8 +348,8 @@ libc_enum! { /// /// B0 is special and will disable the port. #[cfg_attr(target_os = "haiku", repr(u8))] - #[cfg_attr(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "64"), repr(u64))] - #[cfg_attr(all(not(all(any(target_os = "ios", target_os = "macos"), target_pointer_width = "64")), not(target_os = "haiku")), repr(u32))] + #[cfg_attr(all(apple_targets, target_pointer_width = "64"), repr(u64))] + #[cfg_attr(all(not(all(apple_targets, target_pointer_width = "64")), not(target_os = "haiku")), repr(u32))] #[non_exhaustive] pub enum BaudRate { B0, @@ -472,8 +464,7 @@ libc_enum! { #[cfg(any( target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] @@ -678,88 +669,76 @@ libc_bitflags! { ONLRET as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] OFILL as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] OFDEL as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] NL0 as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] NL1 as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] CR0 as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] CR1 as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] CR2 as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] CR3 as tcflag_t; #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] TAB0 as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] TAB1 as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] TAB2 as tcflag_t; #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] TAB3 as tcflag_t; #[cfg(any(target_os = "android", target_os = "linux"))] @@ -767,50 +746,43 @@ libc_bitflags! { XTABS; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] BS0 as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] BS1 as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] VT0 as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] VT1 as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] FF0 as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] FF1 as tcflag_t; #[cfg(any(target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -829,45 +801,39 @@ libc_bitflags! { #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] NLDLY as tcflag_t; // FIXME: Datatype needs to be corrected in libc for mac #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] CRDLY as tcflag_t; #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] TABDLY as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] BSDLY as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] VTDLY as tcflag_t; #[cfg(any(target_os = "android", target_os = "haiku", - target_os = "ios", target_os = "linux", - target_os = "macos"))] + apple_targets))] #[cfg_attr(docsrs, doc(cfg(all())))] FFDLY as tcflag_t; } @@ -878,8 +844,7 @@ libc_bitflags! { pub struct ControlFlags: tcflag_t { #[cfg(any(target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -973,8 +938,7 @@ libc_bitflags! { ICANON; #[cfg(any(target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -989,8 +953,7 @@ libc_bitflags! { FLUSHO; #[cfg(any(target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -1005,8 +968,7 @@ libc_bitflags! { cfg_if! { if #[cfg(any(target_os = "freebsd", target_os = "dragonfly", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd"))] { /// Get input baud rate (see diff --git a/src/sys/uio.rs b/src/sys/uio.rs index 4b55d4200f..3744902489 100644 --- a/src/sys/uio.rs +++ b/src/sys/uio.rs @@ -18,7 +18,11 @@ pub fn writev(fd: Fd, iov: &[IoSlice<'_>]) -> Result { // // Because it is ABI compatible, a pointer cast here is valid let res = unsafe { - libc::writev(fd.as_fd().as_raw_fd(), iov.as_ptr().cast(), iov.len() as c_int) + libc::writev( + fd.as_fd().as_raw_fd(), + iov.as_ptr().cast(), + iov.len() as c_int, + ) }; Errno::result(res).map(|r| r as usize) @@ -33,7 +37,11 @@ pub fn writev(fd: Fd, iov: &[IoSlice<'_>]) -> Result { pub fn readv(fd: Fd, iov: &mut [IoSliceMut<'_>]) -> Result { // SAFETY: same as in writev(), IoSliceMut is ABI-compatible with iovec let res = unsafe { - libc::readv(fd.as_fd().as_raw_fd(), iov.as_ptr().cast(), iov.len() as c_int) + libc::readv( + fd.as_fd().as_raw_fd(), + iov.as_ptr().cast(), + iov.len() as c_int, + ) }; Errno::result(res).map(|r| r as usize) @@ -47,7 +55,11 @@ pub fn readv(fd: Fd, iov: &mut [IoSliceMut<'_>]) -> Result { /// See also: [`writev`](fn.writev.html) and [`pwrite`](fn.pwrite.html) #[cfg(not(any(target_os = "redox", target_os = "haiku")))] #[cfg_attr(docsrs, doc(cfg(all())))] -pub fn pwritev(fd: Fd, iov: &[IoSlice<'_>], offset: off_t) -> Result { +pub fn pwritev( + fd: Fd, + iov: &[IoSlice<'_>], + offset: off_t, +) -> Result { #[cfg(target_env = "uclibc")] let offset = offset as libc::off64_t; // uclibc doesn't use off_t diff --git a/src/sys/utsname.rs b/src/sys/utsname.rs index b48ed9f45e..a6d128bcd7 100644 --- a/src/sys/utsname.rs +++ b/src/sys/utsname.rs @@ -71,7 +71,7 @@ mod test { assert_eq!(super::uname().unwrap().sysname(), "Linux"); } - #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(apple_targets)] #[test] pub fn test_uname_darwin() { assert_eq!(super::uname().unwrap().sysname(), "Darwin"); diff --git a/src/sys/wait.rs b/src/sys/wait.rs index f7a63ffcd2..62928bf042 100644 --- a/src/sys/wait.rs +++ b/src/sys/wait.rs @@ -27,10 +27,9 @@ libc_bitflags!( #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "haiku", - target_os = "ios", + apple_targets, target_os = "linux", target_os = "redox", - target_os = "macos", target_os = "netbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] WEXITED; @@ -42,10 +41,9 @@ libc_bitflags!( #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "haiku", - target_os = "ios", + apple_targets, target_os = "linux", target_os = "redox", - target_os = "macos", target_os = "netbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] WSTOPPED; @@ -53,10 +51,9 @@ libc_bitflags!( #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "haiku", - target_os = "ios", + apple_targets, target_os = "linux", target_os = "redox", - target_os = "macos", target_os = "netbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] WNOWAIT; @@ -378,7 +375,9 @@ pub fn waitid(id: Id, flags: WaitPidFlag) -> Result { Id::PGid(pid) => (libc::P_PGID, pid.as_raw() as libc::id_t), #[cfg(any(target_os = "android", target_os = "linux"))] Id::PIDFd(fd) => (libc::P_PIDFD, fd.as_raw_fd() as libc::id_t), - Id::_Unreachable(_) => unreachable!("This variant could never be constructed"), + Id::_Unreachable(_) => { + unreachable!("This variant could never be constructed") + } }; let siginfo = unsafe { diff --git a/src/time.rs b/src/time.rs index 2e03c46cf4..e35e29d9ce 100644 --- a/src/time.rs +++ b/src/time.rs @@ -54,12 +54,7 @@ impl ClockId { } /// Sets time to `timespec` on the clock id - #[cfg(not(any( - target_os = "macos", - target_os = "ios", - target_os = "redox", - target_os = "hermit", - )))] + #[cfg(not(any(apple_targets, target_os = "redox", target_os = "hermit",)))] #[cfg_attr(docsrs, doc(cfg(all())))] pub fn set_time(self, timespec: TimeSpec) -> Result<()> { clock_settime(self, timespec) @@ -117,8 +112,7 @@ impl ClockId { target_os = "android", target_os = "emscripten", target_os = "fuchsia", - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "freebsd", target_os = "dragonfly", target_os = "redox", @@ -178,8 +172,7 @@ impl ClockId { target_os = "android", target_os = "emscripten", target_os = "fuchsia", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "freebsd", target_os = "dragonfly", target_os = "linux" @@ -246,12 +239,7 @@ pub fn clock_gettime(clock_id: ClockId) -> Result { /// Set the time of the specified clock, (see /// [clock_settime(2)](https://pubs.opengroup.org/onlinepubs/7908799/xsh/clock_settime.html)). -#[cfg(not(any( - target_os = "macos", - target_os = "ios", - target_os = "redox", - target_os = "hermit", -)))] +#[cfg(not(any(apple_targets, target_os = "redox", target_os = "hermit",)))] #[cfg_attr(docsrs, doc(cfg(all())))] pub fn clock_settime(clock_id: ClockId, timespec: TimeSpec) -> Result<()> { let ret = diff --git a/src/unistd.rs b/src/unistd.rs index 69dd83d6f9..9397d41ba9 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -20,8 +20,7 @@ use crate::fcntl::{fcntl, FcntlArg::F_SETFD, FdFlag, OFlag}; target_os = "netbsd", target_os = "freebsd", target_os = "dragonfly", - target_os = "macos", - target_os = "ios" + apple_targets, ) ))] use crate::sys::stat::FileFlag; @@ -587,8 +586,7 @@ pub fn mkfifo(path: &P, mode: Mode) -> Result<()> { // mkfifoat is not implemented in OSX or android #[inline] #[cfg(not(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "haiku", target_os = "android", target_os = "redox" @@ -1028,8 +1026,7 @@ pub fn sethostname>(name: S) -> Result<()> { if #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "aix", target_os = "solaris", ))] { type sethostname_len_t = c_int; @@ -1565,7 +1562,7 @@ feature! { /// **Note:** This function is not available for Apple platforms. On those /// platforms, checking group membership should be achieved via communication /// with the `opendirectoryd` service. -#[cfg(not(any(target_os = "ios", target_os = "macos")))] +#[cfg(not(apple_targets))] pub fn getgroups() -> Result> { // First get the maximum number of groups. The value returned // shall always be greater than or equal to one and less than or @@ -1650,8 +1647,7 @@ pub fn getgroups() -> Result> { /// # try_main().unwrap(); /// ``` #[cfg(not(any( - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "redox", target_os = "haiku" )))] @@ -1661,8 +1657,7 @@ pub fn setgroups(groups: &[Gid]) -> Result<()> { target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd", target_os = "solaris"))] { @@ -1707,8 +1702,7 @@ pub fn setgroups(groups: &[Gid]) -> Result<()> { #[cfg(not(any( target_os = "aix", target_os = "illumos", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "redox" )))] pub fn getgrouplist(user: &CStr, group: Gid) -> Result> { @@ -1719,7 +1713,7 @@ pub fn getgrouplist(user: &CStr, group: Gid) -> Result> { use std::cmp::min; let mut groups = Vec::::with_capacity(min(ngroups_max, 8) as usize); cfg_if! { - if #[cfg(any(target_os = "ios", target_os = "macos"))] { + if #[cfg(apple_targets)] { type getgrouplist_group_t = c_int; } else { type getgrouplist_group_t = gid_t; @@ -1791,14 +1785,13 @@ pub fn getgrouplist(user: &CStr, group: Gid) -> Result> { /// # try_main().unwrap(); /// ``` #[cfg(not(any( - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "redox", target_os = "haiku" )))] pub fn initgroups(user: &CStr, group: Gid) -> Result<()> { cfg_if! { - if #[cfg(any(target_os = "ios", target_os = "macos"))] { + if #[cfg(apple_targets)] { type initgroups_group_t = c_int; } else { type initgroups_group_t = gid_t; @@ -2296,9 +2289,8 @@ pub enum SysconfVar { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -2349,9 +2341,8 @@ pub enum SysconfVar { target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "solaris" @@ -2399,9 +2390,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -2411,9 +2401,8 @@ pub enum SysconfVar { target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "solaris" @@ -2429,9 +2418,8 @@ pub enum SysconfVar { target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "solaris" @@ -2443,9 +2431,8 @@ pub enum SysconfVar { target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "solaris" @@ -2461,9 +2448,8 @@ pub enum SysconfVar { target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd", target_os = "solaris" ))] @@ -2503,9 +2489,8 @@ pub enum SysconfVar { target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd", target_os = "solaris" ))] @@ -2520,9 +2505,8 @@ pub enum SysconfVar { target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd", target_os = "solaris" ))] @@ -2533,9 +2517,8 @@ pub enum SysconfVar { target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "solaris" @@ -2547,9 +2530,8 @@ pub enum SysconfVar { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -2559,9 +2541,8 @@ pub enum SysconfVar { target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd", target_os = "solaris" @@ -2584,9 +2565,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2596,9 +2576,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2608,9 +2587,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2620,18 +2598,16 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] /// The implementation supports the Process Sporadic Server option. _POSIX_SPORADIC_SERVER = libc::_SC_SPORADIC_SERVER, #[cfg(any( - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -2649,9 +2625,8 @@ pub enum SysconfVar { #[cfg_attr(docsrs, doc(cfg(all())))] _POSIX_THREAD_ATTR_STACKSIZE = libc::_SC_THREAD_ATTR_STACKSIZE, #[cfg(any( - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2674,9 +2649,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2707,9 +2681,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -2722,9 +2695,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -2737,9 +2709,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -2748,18 +2719,16 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] /// The implementation supports the Trace Event Filter option. _POSIX_TRACE_EVENT_FILTER = libc::_SC_TRACE_EVENT_FILTER, #[cfg(any( - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -2767,9 +2736,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -2778,34 +2746,30 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] /// The implementation supports the Trace Log option. _POSIX_TRACE_LOG = libc::_SC_TRACE_LOG, #[cfg(any( - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] _POSIX_TRACE_NAME_MAX = libc::_SC_TRACE_NAME_MAX, #[cfg(any( - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] _POSIX_TRACE_SYS_MAX = libc::_SC_TRACE_SYS_MAX, #[cfg(any( - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -2813,9 +2777,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -2828,9 +2791,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2841,9 +2803,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2855,9 +2816,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2868,9 +2828,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2907,9 +2866,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2920,9 +2878,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2932,9 +2889,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2944,9 +2900,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2956,9 +2911,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -2968,9 +2922,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -3013,9 +2966,8 @@ pub enum SysconfVar { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -3027,9 +2979,8 @@ pub enum SysconfVar { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -3038,9 +2989,8 @@ pub enum SysconfVar { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -3049,9 +2999,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd" ))] @@ -3066,9 +3015,8 @@ pub enum SysconfVar { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -3078,9 +3026,8 @@ pub enum SysconfVar { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -3091,9 +3038,8 @@ pub enum SysconfVar { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -3102,9 +3048,8 @@ pub enum SysconfVar { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -3114,9 +3059,8 @@ pub enum SysconfVar { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -3130,9 +3074,8 @@ pub enum SysconfVar { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -3142,9 +3085,8 @@ pub enum SysconfVar { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -3154,9 +3096,8 @@ pub enum SysconfVar { target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "openbsd" ))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -3946,8 +3887,7 @@ feature! { /// /// See also [getpeereid(3)](https://www.freebsd.org/cgi/man.cgi?query=getpeereid) #[cfg(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", @@ -3974,8 +3914,7 @@ feature! { target_os = "netbsd", target_os = "freebsd", target_os = "dragonfly", - target_os = "macos", - target_os = "ios" + apple_targets ))] pub fn chflags(path: &P, flags: FileFlag) -> Result<()> { let res = path.with_nix_path(|cstr| unsafe { diff --git a/test/sys/mod.rs b/test/sys/mod.rs index 20312120a6..ae4ff953fe 100644 --- a/test/sys/mod.rs +++ b/test/sys/mod.rs @@ -7,9 +7,8 @@ mod test_signal; // cases on DragonFly. #[cfg(any( target_os = "freebsd", - target_os = "ios", + apple_targets, all(target_os = "linux", not(target_env = "uclibc")), - target_os = "macos", target_os = "netbsd" ))] mod test_aio; diff --git a/test/sys/test_aio_drop.rs b/test/sys/test_aio_drop.rs index bbe6623fd7..54106dd168 100644 --- a/test/sys/test_aio_drop.rs +++ b/test/sys/test_aio_drop.rs @@ -8,8 +8,7 @@ not(target_env = "uclibc"), any( target_os = "linux", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "freebsd", target_os = "netbsd" ) diff --git a/test/sys/test_ioctl.rs b/test/sys/test_ioctl.rs index 40f60cfdbc..b9d9f9f0c3 100644 --- a/test/sys/test_ioctl.rs +++ b/test/sys/test_ioctl.rs @@ -137,8 +137,7 @@ mod linux { #[cfg(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd" ))] diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 49e46889b1..ddd4f7c730 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -1604,7 +1604,7 @@ pub fn test_unnamed_unixdomain_autobind() { } // Test creating and using named system control sockets -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(apple_targets)] #[test] pub fn test_syscontrol() { use nix::errno::Errno; @@ -1633,9 +1633,8 @@ pub fn test_syscontrol() { #[cfg(any( target_os = "android", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd", ))] @@ -1667,9 +1666,8 @@ fn loopback_address( #[cfg(any( target_os = "android", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", ))] // qemu doesn't seem to be emulating this correctly in these architectures @@ -1762,8 +1760,7 @@ pub fn test_recv_ipv4pktinfo() { #[cfg(any( target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd", ))] @@ -2053,9 +2050,8 @@ pub fn test_recvif_ipv6() { #[cfg(any( target_os = "android", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos", target_os = "netbsd", target_os = "openbsd", ))] diff --git a/test/sys/test_sockopt.rs b/test/sys/test_sockopt.rs index 90432f9ab9..a3100c99a8 100644 --- a/test/sys/test_sockopt.rs +++ b/test/sys/test_sockopt.rs @@ -29,12 +29,7 @@ pub fn test_local_peercred_seqpacket() { assert_eq!(Gid::from_raw(xucred.groups()[0]), Gid::current()); } -#[cfg(any( - target_os = "dragonfly", - target_os = "freebsd", - target_os = "macos", - target_os = "ios" -))] +#[cfg(any(target_os = "dragonfly", target_os = "freebsd", apple_targets))] #[test] pub fn test_local_peercred_stream() { use nix::{ @@ -55,7 +50,7 @@ pub fn test_local_peercred_stream() { assert_eq!(Gid::from_raw(xucred.groups()[0]), Gid::current()); } -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple_targets)] #[test] pub fn test_local_peer_pid() { use nix::sys::socket::socketpair; @@ -331,7 +326,7 @@ fn test_ttl_opts() { } #[test] -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple_targets)] fn test_dontfrag_opts() { let fd4 = socket( AddressFamily::Inet, @@ -361,12 +356,7 @@ fn test_dontfrag_opts() { } #[test] -#[cfg(any( - target_os = "android", - target_os = "ios", - target_os = "linux", - target_os = "macos", -))] +#[cfg(any(target_os = "android", apple_targets, target_os = "linux",))] // Disable the test under emulation because it fails in Cirrus-CI. Lack // of QEMU support is suspected. #[cfg_attr(qemu, ignore)] diff --git a/test/test.rs b/test/test.rs index 7e73bb3056..c8c9bf1aa7 100644 --- a/test/test.rs +++ b/test/test.rs @@ -42,9 +42,8 @@ mod test_sched; target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", + apple_targets, target_os = "linux", - target_os = "macos" ))] mod test_sendfile; mod test_stat; diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index 1c5cb4f9b3..112d03a38a 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -562,12 +562,7 @@ mod test_posix_fallocate { } } -#[cfg(any( - target_os = "dragonfly", - target_os = "netbsd", - target_os = "macos", - target_os = "ios" -))] +#[cfg(any(target_os = "dragonfly", target_os = "netbsd", apple_targets))] #[test] fn test_f_get_path() { use nix::fcntl::*; @@ -585,7 +580,7 @@ fn test_f_get_path() { ); } -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(apple_targets)] #[test] fn test_f_get_path_nofirmlink() { use nix::fcntl::*; diff --git a/test/test_sendfile.rs b/test/test_sendfile.rs index a594f18e39..99493f0a60 100644 --- a/test/test_sendfile.rs +++ b/test/test_sendfile.rs @@ -8,7 +8,11 @@ cfg_if! { if #[cfg(any(target_os = "android", target_os = "linux"))] { use nix::unistd::{pipe, read}; use std::os::unix::io::AsRawFd; - } else if #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "ios", target_os = "macos"))] { + } else if #[cfg(any( + target_os = "dragonfly", + target_os = "freebsd", + apple_targets, + ))] { use std::net::Shutdown; use std::os::unix::net::UnixStream; } @@ -152,7 +156,7 @@ fn test_sendfile_dragonfly() { assert_eq!(expected_string, read_string); } -#[cfg(any(target_os = "ios", target_os = "macos"))] +#[cfg(apple_targets)] #[test] fn test_sendfile_darwin() { // Declare the content diff --git a/test/test_stat.rs b/test/test_stat.rs index a61d4068b3..6bae35e188 100644 --- a/test/test_stat.rs +++ b/test/test_stat.rs @@ -21,8 +21,7 @@ use nix::errno::Errno; use nix::fcntl; #[cfg(any( target_os = "linux", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "freebsd", target_os = "netbsd" ))] @@ -235,8 +234,7 @@ fn test_utimes() { #[test] #[cfg(any( target_os = "linux", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "freebsd", target_os = "netbsd" ))] @@ -365,8 +363,7 @@ fn test_mkdirat_fail() { #[cfg(not(any( target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "haiku", target_os = "redox" )))] @@ -387,8 +384,7 @@ fn test_mknod() { target_os = "dragonfly", target_os = "freebsd", target_os = "illumos", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "haiku", target_os = "redox" )))] diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 1378a15ced..44cf460253 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -126,8 +126,7 @@ fn test_mkfifo_directory() { #[test] #[cfg(not(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "android", target_os = "redox", target_os = "haiku" @@ -147,8 +146,7 @@ fn test_mkfifoat_none() { #[test] #[cfg(not(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "android", target_os = "redox", target_os = "haiku" @@ -171,8 +169,7 @@ fn test_mkfifoat() { #[test] #[cfg(not(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "android", target_os = "redox", target_os = "haiku" @@ -187,8 +184,7 @@ fn test_mkfifoat_directory_none() { #[test] #[cfg(not(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "android", target_os = "redox", target_os = "haiku" @@ -235,8 +231,7 @@ mod linux_android { #[test] // `getgroups()` and `setgroups()` do not behave as expected on Apple platforms #[cfg(not(any( - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "redox", target_os = "fuchsia", target_os = "haiku" @@ -264,8 +259,7 @@ fn test_setgroups() { #[test] // `getgroups()` and `setgroups()` do not behave as expected on Apple platforms #[cfg(not(any( - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "redox", target_os = "fuchsia", target_os = "haiku", @@ -413,8 +407,7 @@ cfg_if! { execve_test_factory!(test_execve, execve, CString::new("/bin/sh").unwrap().as_c_str()); execve_test_factory!(test_fexecve, fexecve, File::open("/bin/sh").unwrap().into_raw_fd()); } else if #[cfg(any(target_os = "illumos", - target_os = "ios", - target_os = "macos", + apple_targets, target_os = "netbsd", target_os = "openbsd", target_os = "solaris"))] { @@ -988,12 +981,7 @@ fn test_linkat_newdirfd_none() { } #[test] -#[cfg(not(any( - target_os = "ios", - target_os = "macos", - target_os = "redox", - target_os = "haiku" -)))] +#[cfg(not(any(apple_targets, target_os = "redox", target_os = "haiku")))] fn test_linkat_no_follow_symlink() { let _m = crate::CWD_LOCK.read(); @@ -1254,8 +1242,7 @@ fn test_ttyname_not_pty() { #[test] #[cfg(any( - target_os = "macos", - target_os = "ios", + apple_targets, target_os = "freebsd", target_os = "openbsd", target_os = "netbsd",