Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo fmt --all -- "**/*.rs" #2211

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sys/epoll.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::errno::Errno;
use crate::Result;
pub use crate::poll_timeout::PollTimeout as EpollTimeout;
use crate::Result;
use libc::{self, c_int};
use std::mem;
use std::os::unix::io::{AsFd, AsRawFd, FromRawFd, OwnedFd, RawFd};
Expand Down
34 changes: 19 additions & 15 deletions src/sys/fanotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
//! For more documentation, please read
//! [fanotify(7)](https://man7.org/linux/man-pages/man7/fanotify.7.html).

use crate::{NixPath, Result};
use crate::errno::Errno;
use crate::fcntl::{OFlag, at_rawfd};
use crate::fcntl::{at_rawfd, OFlag};
use crate::unistd::{close, read, write};
use crate::{NixPath, Result};
use std::marker::PhantomData;
use std::mem::{MaybeUninit, size_of};
use std::mem::{size_of, MaybeUninit};
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, OwnedFd, RawFd};
use std::ptr;

Expand Down Expand Up @@ -288,11 +288,16 @@ impl Fanotify {
/// Returns a Result containing a Fanotify instance.
///
/// For more information, see [fanotify_init(2)](https://man7.org/linux/man-pages/man7/fanotify_init.2.html).
pub fn init(flags: InitFlags, event_f_flags: EventFFlags) -> Result<Fanotify> {
pub fn init(
flags: InitFlags,
event_f_flags: EventFFlags,
) -> Result<Fanotify> {
let res = Errno::result(unsafe {
libc::fanotify_init(flags.bits(), event_f_flags.bits())
});
res.map(|fd| Fanotify { fd: unsafe { OwnedFd::from_raw_fd(fd) }})
res.map(|fd| Fanotify {
fd: unsafe { OwnedFd::from_raw_fd(fd) },
})
}

/// Add, remove, or modify an fanotify mark on a filesystem object.
Expand Down Expand Up @@ -386,22 +391,21 @@ impl Fanotify {
/// available on a group that has been initialized with the flag
/// `InitFlags::FAN_NONBLOCK`, thus making this method nonblocking.
pub fn write_response(&self, response: FanotifyResponse) -> Result<()> {
write(
self.fd.as_fd(),
unsafe {
std::slice::from_raw_parts(
(&response.inner as *const libc::fanotify_response).cast(),
size_of::<libc::fanotify_response>(),
)
},
)?;
write(self.fd.as_fd(), unsafe {
std::slice::from_raw_parts(
(&response.inner as *const libc::fanotify_response).cast(),
size_of::<libc::fanotify_response>(),
)
})?;
Ok(())
}
}

impl FromRawFd for Fanotify {
unsafe fn from_raw_fd(fd: RawFd) -> Self {
Fanotify { fd: unsafe { OwnedFd::from_raw_fd(fd) }}
Fanotify {
fd: unsafe { OwnedFd::from_raw_fd(fd) },
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sys/ptrace/bsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ unsafe fn ptrace_other(
addr,
data,
))
.map(|_| 0)
.map(|_| 0)
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/sys/sendfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ use crate::Result;
///
/// For more information, see [the sendfile(2) man page.](https://man7.org/linux/man-pages/man2/sendfile.2.html) for Linux,
/// see [the sendfile(2) man page.](https://docs.oracle.com/cd/E88353_01/html/E37843/sendfile-3c.html) for Solaris.
#[cfg(any(target_os = "android", target_os = "linux", target_os = "solaris", target_os = "illumos"))]
#[cfg(any(
target_os = "android",
target_os = "linux",
target_os = "solaris",
target_os = "illumos",
))]
pub fn sendfile<F1: AsFd, F2: AsFd>(
out_fd: F1,
in_fd: F2,
Expand Down
73 changes: 19 additions & 54 deletions src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,7 @@ pub enum AddressFamily {
#[cfg(bsd)]
Hylink = libc::AF_HYLINK,
/// Link layer interface
#[cfg(any(
bsd,
target_os = "illumos",
))]
#[cfg(any(bsd, target_os = "illumos"))]
Link = libc::AF_LINK,
/// connection-oriented IP, aka ST II
#[cfg(bsd)]
Expand Down Expand Up @@ -293,10 +290,7 @@ impl AddressFamily {
libc::PF_ROUTE => Some(AddressFamily::Route),
#[cfg(linux_android)]
libc::AF_PACKET => Some(AddressFamily::Packet),
#[cfg(any(
bsd,
target_os = "illumos",
))]
#[cfg(any(bsd, target_os = "illumos"))]
libc::AF_LINK => Some(AddressFamily::Link),
#[cfg(any(
target_os = "android",
Expand Down Expand Up @@ -863,11 +857,7 @@ impl SockaddrIn {
/// Creates a new socket address from IPv4 octets and a port number.
pub fn new(a: u8, b: u8, c: u8, d: u8, port: u16) -> Self {
Self(libc::sockaddr_in {
#[cfg(any(
bsd,
target_os = "aix",
target_os = "haiku",
))]
#[cfg(any(bsd, target_os = "aix", target_os = "haiku"))]
sin_len: Self::size() as u8,
sin_family: AddressFamily::Inet as sa_family_t,
sin_port: u16::to_be(port),
Expand Down Expand Up @@ -936,11 +926,7 @@ impl fmt::Display for SockaddrIn {
impl From<net::SocketAddrV4> for SockaddrIn {
fn from(addr: net::SocketAddrV4) -> Self {
Self(libc::sockaddr_in {
#[cfg(any(
bsd,
target_os = "haiku",
target_os = "hermit",
))]
#[cfg(any(bsd, target_os = "haiku", target_os = "hermit"))]
sin_len: mem::size_of::<libc::sockaddr_in>() as u8,
sin_family: AddressFamily::Inet as sa_family_t,
sin_port: addr.port().to_be(), // network byte order
Expand Down Expand Up @@ -1060,11 +1046,7 @@ impl From<net::SocketAddrV6> for SockaddrIn6 {
fn from(addr: net::SocketAddrV6) -> Self {
#[allow(clippy::needless_update)] // It isn't needless on Illumos
Self(libc::sockaddr_in6 {
#[cfg(any(
bsd,
target_os = "haiku",
target_os = "hermit",
))]
#[cfg(any(bsd, target_os = "haiku", target_os = "hermit"))]
sin6_len: mem::size_of::<libc::sockaddr_in6>() as u8,
sin6_family: AddressFamily::Inet6 as sa_family_t,
sin6_port: addr.port().to_be(), // network byte order
Expand Down Expand Up @@ -1198,15 +1180,11 @@ impl SockaddrLike for SockaddrStorage {
libc::AF_INET6 => unsafe {
SockaddrIn6::from_raw(addr, l).map(|sin6| Self { sin6 })
},
#[cfg(any(
bsd,
target_os = "illumos",
target_os = "haiku",
))]
#[cfg(any(bsd, target_os = "illumos", target_os = "haiku"))]
#[cfg(feature = "net")]
libc::AF_LINK => unsafe {
LinkAddr::from_raw(addr, l).map(|dl| Self { dl })
}
},
#[cfg(linux_android)]
libc::AF_NETLINK => unsafe {
NetlinkAddr::from_raw(addr, l).map(|nl| Self { nl })
Expand All @@ -1219,12 +1197,16 @@ impl SockaddrLike for SockaddrStorage {
#[cfg(feature = "net")]
libc::AF_PACKET => unsafe {
LinkAddr::from_raw(addr, l).map(|dl| Self { dl })
}
},
#[cfg(all(feature = "ioctl", apple_targets))]
libc::AF_SYSTEM => unsafe {
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 => unsafe {
VsockAddr::from_raw(addr, l).map(|vsock| Self { vsock })
},
Expand Down Expand Up @@ -1368,10 +1350,7 @@ impl SockaddrStorage {
as_link_addr, as_link_addr_mut, LinkAddr,
AddressFamily::Packet, libc::sockaddr_ll, dl}

#[cfg(any(
bsd,
target_os = "illumos",
))]
#[cfg(any(bsd, target_os = "illumos"))]
#[cfg(feature = "net")]
accessors! {
as_link_addr, as_link_addr_mut, LinkAddr,
Expand Down Expand Up @@ -1425,10 +1404,7 @@ impl fmt::Display for SockaddrStorage {
libc::AF_INET => self.sin.fmt(f),
#[cfg(feature = "net")]
libc::AF_INET6 => self.sin6.fmt(f),
#[cfg(any(
bsd,
target_os = "illumos",
))]
#[cfg(any(bsd, target_os = "illumos"))]
#[cfg(feature = "net")]
libc::AF_LINK => self.dl.fmt(f),
#[cfg(linux_android)]
Expand Down Expand Up @@ -1498,10 +1474,7 @@ impl Hash for SockaddrStorage {
libc::AF_INET => self.sin.hash(s),
#[cfg(feature = "net")]
libc::AF_INET6 => self.sin6.hash(s),
#[cfg(any(
bsd,
target_os = "illumos",
))]
#[cfg(any(bsd, target_os = "illumos"))]
#[cfg(feature = "net")]
libc::AF_LINK => self.dl.hash(s),
#[cfg(linux_android)]
Expand Down Expand Up @@ -1539,10 +1512,7 @@ impl PartialEq for SockaddrStorage {
(libc::AF_INET, libc::AF_INET) => self.sin == other.sin,
#[cfg(feature = "net")]
(libc::AF_INET6, libc::AF_INET6) => self.sin6 == other.sin6,
#[cfg(any(
bsd,
target_os = "illumos",
))]
#[cfg(any(bsd, target_os = "illumos"))]
#[cfg(feature = "net")]
(libc::AF_LINK, libc::AF_LINK) => self.dl == other.dl,
#[cfg(linux_android)]
Expand Down Expand Up @@ -1980,12 +1950,7 @@ mod datalink {
}
}

#[cfg(any(
bsd,
target_os = "illumos",
target_os = "haiku",
target_os = "aix",
))]
#[cfg(any(bsd, target_os = "illumos", target_os = "haiku", target_os = "aix"))]
mod datalink {
feature! {
#![feature = "net"]
Expand Down