diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-12-04 20:55:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-04 20:55:47 +0000 |
commit | 3286c4df4871505c46d41f1aec10e984aa07e960 (patch) | |
tree | 0ca13e8ce6a6617755c68e3e0592a4627f80634a /src/sys | |
parent | 40c85353a18a3f3e5a3367e2f76a9718b955a026 (diff) | |
parent | 5fd4b8a4d4fdfa79c59796f73ba24a72a579bb49 (diff) | |
download | nix-3286c4df4871505c46d41f1aec10e984aa07e960.zip |
Merge #1909
1909: More annoying formatting changes r=asomers a=SUPERCILEX
Extracted from https://github.com/nix-rust/nix/pull/1862
Co-authored-by: Alex Saveau <saveau.alexandre@gmail.com>
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/mman.rs | 13 | ||||
-rw-r--r-- | src/sys/socket/addr.rs | 64 | ||||
-rw-r--r-- | src/sys/socket/sockopt.rs | 10 |
3 files changed, 46 insertions, 41 deletions
diff --git a/src/sys/mman.rs b/src/sys/mman.rs index 2bee0916..d4c6ecb0 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -8,7 +8,7 @@ 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::{os::unix::io::RawFd, num::NonZeroUsize}; +use std::{num::NonZeroUsize, os::unix::io::RawFd}; libc_bitflags! { /// Desired memory protection of a memory mapping. @@ -424,12 +424,11 @@ pub unsafe fn mmap( fd: RawFd, offset: off_t, ) -> Result<*mut c_void> { - let ptr = addr.map_or( - std::ptr::null_mut(), - |a| usize::from(a) as *mut c_void - ); - - let ret = libc::mmap(ptr, length.into(), prot.bits(), flags.bits(), fd, offset); + let ptr = + addr.map_or(std::ptr::null_mut(), |a| usize::from(a) as *mut c_void); + + let ret = + libc::mmap(ptr, length.into(), prot.bits(), flags.bits(), fd, offset); if ret == libc::MAP_FAILED { Err(Errno::last()) diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 970e8381..d83adcfe 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -42,9 +42,7 @@ pub(crate) const fn ipv4addr_to_libc(addr: net::Ipv4Addr) -> libc::in_addr { static_assertions::assert_eq_size!(net::Ipv4Addr, libc::in_addr); // Safe because both types have the same memory layout, and no fancy Drop // impls. - unsafe { - mem::transmute(addr) - } + unsafe { mem::transmute(addr) } } /// Convert a std::net::Ipv6Addr into the libc form. @@ -52,9 +50,7 @@ pub(crate) const fn ipv4addr_to_libc(addr: net::Ipv4Addr) -> libc::in_addr { pub(crate) const fn ipv6addr_to_libc(addr: &net::Ipv6Addr) -> libc::in6_addr { static_assertions::assert_eq_size!(net::Ipv6Addr, libc::in6_addr); // Safe because both are Newtype wrappers around the same libc type - unsafe { - mem::transmute(*addr) - } + unsafe { mem::transmute(*addr) } } /// These constants specify the protocol family to be used @@ -79,7 +75,11 @@ pub enum AddressFamily { #[cfg_attr(docsrs, doc(cfg(all())))] Netlink = libc::AF_NETLINK, /// Kernel interface for interacting with the routing table - #[cfg(not(any(target_os = "redox", target_os = "linux", target_os = "android")))] + #[cfg(not(any( + target_os = "redox", + target_os = "linux", + target_os = "android" + )))] Route = libc::PF_ROUTE, /// Low level packet interface (see [`packet(7)`](https://man7.org/linux/man-pages/man7/packet.7.html)) #[cfg(any( @@ -422,7 +422,11 @@ impl AddressFamily { libc::AF_NETLINK => Some(AddressFamily::Netlink), #[cfg(any(target_os = "macos", target_os = "macos"))] libc::AF_SYSTEM => Some(AddressFamily::System), - #[cfg(not(any(target_os = "redox", target_os = "linux", target_os = "android")))] + #[cfg(not(any( + target_os = "redox", + target_os = "linux", + target_os = "android" + )))] libc::PF_ROUTE => Some(AddressFamily::Route), #[cfg(any(target_os = "android", target_os = "linux"))] libc::AF_PACKET => Some(AddressFamily::Packet), @@ -592,10 +596,11 @@ impl UnixAddr { pub fn new_unnamed() -> UnixAddr { let ret = libc::sockaddr_un { sun_family: AddressFamily::Unix as sa_family_t, - .. unsafe { mem::zeroed() } + ..unsafe { mem::zeroed() } }; - let sun_len: u8 = offset_of!(libc::sockaddr_un, sun_path).try_into().unwrap(); + let sun_len: u8 = + offset_of!(libc::sockaddr_un, sun_path).try_into().unwrap(); unsafe { UnixAddr::from_raw_parts(ret, sun_len) } } @@ -1268,7 +1273,9 @@ impl SockaddrLike for SockaddrStorage { if i32::from(ss.ss_family) == libc::AF_UNIX { // Safe because we UnixAddr is strictly smaller than // SockaddrStorage, and we just initialized the structure. - (*(&mut ss as *mut libc::sockaddr_storage as *mut UnixAddr)).sun_len = len as u8; + (*(&mut ss as *mut libc::sockaddr_storage + as *mut UnixAddr)) + .sun_len = len as u8; } Some(Self { ss }) } @@ -1343,7 +1350,7 @@ impl SockaddrLike for SockaddrStorage { // The UnixAddr type knows its own length Some(ua) => ua.len(), // For all else, we're just a boring SockaddrStorage - None => mem::size_of_val(self) as libc::socklen_t + None => mem::size_of_val(self) as libc::socklen_t, } } } @@ -1403,12 +1410,13 @@ impl SockaddrStorage { } } // Sanity checks - if self.family() != Some(AddressFamily::Unix) || - len < offset_of!(libc::sockaddr_un, sun_path) || - len > mem::size_of::<libc::sockaddr_un>() { + if self.family() != Some(AddressFamily::Unix) + || len < offset_of!(libc::sockaddr_un, sun_path) + || len > mem::size_of::<libc::sockaddr_un>() + { None } else { - Some(unsafe{&self.su}) + Some(unsafe { &self.su }) } } @@ -1432,12 +1440,13 @@ impl SockaddrStorage { } } // Sanity checks - if self.family() != Some(AddressFamily::Unix) || - len < offset_of!(libc::sockaddr_un, sun_path) || - len > mem::size_of::<libc::sockaddr_un>() { + if self.family() != Some(AddressFamily::Unix) + || len < offset_of!(libc::sockaddr_un, sun_path) + || len > mem::size_of::<libc::sockaddr_un>() + { None } else { - Some(unsafe{&mut self.su}) + Some(unsafe { &mut self.su }) } } @@ -2525,9 +2534,8 @@ mod tests { fn from_sockaddr_un_named() { let ua = UnixAddr::new("/var/run/mysock").unwrap(); let ptr = ua.as_ptr() as *const libc::sockaddr; - let ss = unsafe { - SockaddrStorage::from_raw(ptr, Some(ua.len())) - }.unwrap(); + let ss = unsafe { SockaddrStorage::from_raw(ptr, Some(ua.len())) } + .unwrap(); assert_eq!(ss.len(), ua.len()); } @@ -2537,9 +2545,8 @@ mod tests { let name = String::from("nix\0abstract\0test"); let ua = UnixAddr::new_abstract(name.as_bytes()).unwrap(); let ptr = ua.as_ptr() as *const libc::sockaddr; - let ss = unsafe { - SockaddrStorage::from_raw(ptr, Some(ua.len())) - }.unwrap(); + let ss = unsafe { SockaddrStorage::from_raw(ptr, Some(ua.len())) } + .unwrap(); assert_eq!(ss.len(), ua.len()); } @@ -2548,9 +2555,8 @@ mod tests { fn from_sockaddr_un_abstract_unnamed() { let ua = UnixAddr::new_unnamed(); let ptr = ua.as_ptr() as *const libc::sockaddr; - let ss = unsafe { - SockaddrStorage::from_raw(ptr, Some(ua.len())) - }.unwrap(); + let ss = unsafe { SockaddrStorage::from_raw(ptr, Some(ua.len())) } + .unwrap(); assert_eq!(ss.len(), ua.len()); } } diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index 06e9ee45..4e0abfbe 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -6,13 +6,13 @@ use crate::Result; use cfg_if::cfg_if; use libc::{self, c_int, c_void, socklen_t}; use std::ffi::{OsStr, OsString}; -use std::{ - convert::TryFrom, - mem::{self, MaybeUninit} -}; #[cfg(target_family = "unix")] use std::os::unix::ffi::OsStrExt; use std::os::unix::io::RawFd; +use std::{ + convert::TryFrom, + mem::{self, MaybeUninit}, +}; // Constants // TCP_CA_NAME_MAX isn't defined in user space include files @@ -107,7 +107,7 @@ macro_rules! getsockopt_impl { match <$ty>::try_from(getter.assume_init()) { Err(_) => Err(Errno::EINVAL), - Ok(r) => Ok(r) + Ok(r) => Ok(r), } } } |