summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/backend/libc/net/addr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rustix/src/backend/libc/net/addr.rs')
-rw-r--r--vendor/rustix/src/backend/libc/net/addr.rs49
1 files changed, 24 insertions, 25 deletions
diff --git a/vendor/rustix/src/backend/libc/net/addr.rs b/vendor/rustix/src/backend/libc/net/addr.rs
index d00a48626..bf7d239de 100644
--- a/vendor/rustix/src/backend/libc/net/addr.rs
+++ b/vendor/rustix/src/backend/libc/net/addr.rs
@@ -1,18 +1,16 @@
-//! IPv4, IPv6, and Socket addresses.
+//! Socket address utilities.
-use super::super::c;
+use crate::backend::c;
#[cfg(unix)]
-use crate::ffi::CStr;
-#[cfg(unix)]
-use crate::io;
-#[cfg(unix)]
-use crate::path;
-#[cfg(not(windows))]
-use core::convert::TryInto;
-#[cfg(unix)]
-use core::fmt;
-#[cfg(unix)]
-use core::slice;
+use {
+ crate::ffi::CStr,
+ crate::io,
+ crate::path,
+ core::cmp::Ordering,
+ core::fmt,
+ core::hash::{Hash, Hasher},
+ core::slice,
+};
/// `struct sockaddr_un`
#[cfg(unix)]
@@ -56,14 +54,14 @@ impl SocketAddrUnix {
}
/// Construct a new abstract Unix-domain address from a byte slice.
- #[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(linux_kernel)]
#[inline]
pub fn new_abstract_name(name: &[u8]) -> io::Result<Self> {
let mut unix = Self::init();
if 1 + name.len() > unix.sun_path.len() {
return Err(io::Errno::NAMETOOLONG);
}
- unix.sun_path[0] = b'\0' as c::c_char;
+ unix.sun_path[0] = 0;
for (i, b) in name.iter().enumerate() {
unix.sun_path[1 + i] = *b as c::c_char;
}
@@ -94,11 +92,12 @@ impl SocketAddrUnix {
#[inline]
pub fn path(&self) -> Option<&CStr> {
let len = self.len();
- if len != 0 && self.unix.sun_path[0] != b'\0' as c::c_char {
+ if len != 0 && self.unix.sun_path[0] != 0 {
let end = len as usize - offsetof_sun_path();
let bytes = &self.unix.sun_path[..end];
- // SAFETY: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`. And
- // `from_bytes_with_nul_unchecked` since the string is NUL-terminated.
+ // SAFETY: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`.
+ // And `from_bytes_with_nul_unchecked` since the string is
+ // NUL-terminated.
unsafe {
Some(CStr::from_bytes_with_nul_unchecked(slice::from_raw_parts(
bytes.as_ptr().cast(),
@@ -111,11 +110,11 @@ impl SocketAddrUnix {
}
/// For an abstract address, return the identifier.
- #[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(linux_kernel)]
#[inline]
pub fn abstract_name(&self) -> Option<&[u8]> {
let len = self.len();
- if len != 0 && self.unix.sun_path[0] == b'\0' as c::c_char {
+ if len != 0 && self.unix.sun_path[0] == 0 {
let end = len as usize - offsetof_sun_path();
let bytes = &self.unix.sun_path[1..end];
// SAFETY: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`.
@@ -159,7 +158,7 @@ impl Eq for SocketAddrUnix {}
#[cfg(unix)]
impl PartialOrd for SocketAddrUnix {
#[inline]
- fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let self_len = self.len() - offsetof_sun_path();
let other_len = other.len() - offsetof_sun_path();
self.unix.sun_path[..self_len].partial_cmp(&other.unix.sun_path[..other_len])
@@ -169,7 +168,7 @@ impl PartialOrd for SocketAddrUnix {
#[cfg(unix)]
impl Ord for SocketAddrUnix {
#[inline]
- fn cmp(&self, other: &Self) -> core::cmp::Ordering {
+ fn cmp(&self, other: &Self) -> Ordering {
let self_len = self.len() - offsetof_sun_path();
let other_len = other.len() - offsetof_sun_path();
self.unix.sun_path[..self_len].cmp(&other.unix.sun_path[..other_len])
@@ -177,9 +176,9 @@ impl Ord for SocketAddrUnix {
}
#[cfg(unix)]
-impl core::hash::Hash for SocketAddrUnix {
+impl Hash for SocketAddrUnix {
#[inline]
- fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
+ fn hash<H: Hasher>(&self, state: &mut H) {
let self_len = self.len() - offsetof_sun_path();
self.unix.sun_path[..self_len].hash(state)
}
@@ -191,7 +190,7 @@ impl fmt::Debug for SocketAddrUnix {
if let Some(path) = self.path() {
path.fmt(fmt)
} else {
- #[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(linux_kernel)]
if let Some(name) = self.abstract_name() {
return name.fmt(fmt);
}