]> git.proxmox.com Git - rustc.git/blobdiff - vendor/rustix/src/backend/libc/net/addr.rs
New upstream version 1.70.0+dfsg1
[rustc.git] / vendor / rustix / src / backend / libc / net / addr.rs
index ba64ed279ebb700cfa0ccbaf6b39ec8db08142e2..d00a4862630180f2202062e0eed87fc79106cf10 100644 (file)
@@ -20,14 +20,7 @@ use core::slice;
 #[doc(alias = "sockaddr_un")]
 pub struct SocketAddrUnix {
     pub(crate) unix: c::sockaddr_un,
-    #[cfg(not(any(
-        target_os = "dragonfly",
-        target_os = "freebsd",
-        target_os = "ios",
-        target_os = "macos",
-        target_os = "netbsd",
-        target_os = "openbsd",
-    )))]
+    #[cfg(not(any(bsd, target_os = "haiku")))]
     len: c::socklen_t,
 }
 
@@ -50,28 +43,14 @@ impl SocketAddrUnix {
             unix.sun_path[i] = *b as c::c_char;
         }
 
-        #[cfg(any(
-            target_os = "dragonfly",
-            target_os = "freebsd",
-            target_os = "ios",
-            target_os = "macos",
-            target_os = "netbsd",
-            target_os = "openbsd",
-        ))]
+        #[cfg(any(bsd, target_os = "haiku"))]
         {
             unix.sun_len = (offsetof_sun_path() + bytes.len()).try_into().unwrap();
         }
 
         Ok(Self {
             unix,
-            #[cfg(not(any(
-                target_os = "dragonfly",
-                target_os = "freebsd",
-                target_os = "ios",
-                target_os = "macos",
-                target_os = "netbsd",
-                target_os = "openbsd",
-            )))]
+            #[cfg(not(any(bsd, target_os = "haiku")))]
             len: (offsetof_sun_path() + bytes.len()).try_into().unwrap(),
         })
     }
@@ -92,49 +71,19 @@ impl SocketAddrUnix {
         let len = len.try_into().unwrap();
         Ok(Self {
             unix,
-            #[cfg(not(any(
-                target_os = "dragonfly",
-                target_os = "freebsd",
-                target_os = "ios",
-                target_os = "macos",
-                target_os = "netbsd",
-                target_os = "openbsd",
-            )))]
+            #[cfg(not(any(bsd, target_os = "haiku")))]
             len,
         })
     }
 
     fn init() -> c::sockaddr_un {
         c::sockaddr_un {
-            #[cfg(any(
-                target_os = "dragonfly",
-                target_os = "freebsd",
-                target_os = "haiku",
-                target_os = "ios",
-                target_os = "macos",
-                target_os = "netbsd",
-                target_os = "openbsd",
-            ))]
+            #[cfg(any(bsd, target_os = "haiku"))]
             sun_len: 0,
             sun_family: c::AF_UNIX as _,
-            #[cfg(any(
-                target_os = "dragonfly",
-                target_os = "freebsd",
-                target_os = "ios",
-                target_os = "macos",
-                target_os = "netbsd",
-                target_os = "openbsd",
-            ))]
+            #[cfg(bsd)]
             sun_path: [0; 104],
-            #[cfg(not(any(
-                target_os = "dragonfly",
-                target_os = "freebsd",
-                target_os = "haiku",
-                target_os = "ios",
-                target_os = "macos",
-                target_os = "netbsd",
-                target_os = "openbsd",
-            )))]
+            #[cfg(not(any(bsd, target_os = "haiku")))]
             sun_path: [0; 108],
             #[cfg(target_os = "haiku")]
             sun_path: [0; 126],
@@ -148,7 +97,7 @@ impl SocketAddrUnix {
         if len != 0 && self.unix.sun_path[0] != b'\0' as c::c_char {
             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
+            // 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(
@@ -169,7 +118,7 @@ impl SocketAddrUnix {
         if len != 0 && self.unix.sun_path[0] == b'\0' as c::c_char {
             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]`.
+            // SAFETY: `from_raw_parts` to convert from `&[c_char]` to `&[u8]`.
             unsafe { Some(slice::from_raw_parts(bytes.as_ptr().cast(), bytes.len())) }
         } else {
             None
@@ -178,25 +127,11 @@ impl SocketAddrUnix {
 
     #[inline]
     pub(crate) fn addr_len(&self) -> c::socklen_t {
-        #[cfg(not(any(
-            target_os = "dragonfly",
-            target_os = "freebsd",
-            target_os = "ios",
-            target_os = "macos",
-            target_os = "netbsd",
-            target_os = "openbsd",
-        )))]
+        #[cfg(not(any(bsd, target_os = "haiku")))]
         {
             self.len
         }
-        #[cfg(any(
-            target_os = "dragonfly",
-            target_os = "freebsd",
-            target_os = "ios",
-            target_os = "macos",
-            target_os = "netbsd",
-            target_os = "openbsd",
-        ))]
+        #[cfg(any(bsd, target_os = "haiku"))]
         {
             c::socklen_t::from(self.unix.sun_len)
         }
@@ -274,54 +209,15 @@ pub type SocketAddrStorage = c::sockaddr_storage;
 #[inline]
 pub(crate) fn offsetof_sun_path() -> usize {
     let z = c::sockaddr_un {
-        #[cfg(any(
-            target_os = "dragonfly",
-            target_os = "freebsd",
-            target_os = "haiku",
-            target_os = "ios",
-            target_os = "macos",
-            target_os = "netbsd",
-            target_os = "openbsd",
-        ))]
+        #[cfg(any(bsd, target_os = "haiku"))]
         sun_len: 0_u8,
-        #[cfg(any(
-            target_os = "dragonfly",
-            target_os = "freebsd",
-            target_os = "haiku",
-            target_os = "ios",
-            target_os = "macos",
-            target_os = "netbsd",
-            target_os = "openbsd",
-        ))]
+        #[cfg(any(bsd, target_os = "haiku"))]
         sun_family: 0_u8,
-        #[cfg(not(any(
-            target_os = "dragonfly",
-            target_os = "freebsd",
-            target_os = "haiku",
-            target_os = "ios",
-            target_os = "macos",
-            target_os = "netbsd",
-            target_os = "openbsd",
-        )))]
+        #[cfg(not(any(bsd, target_os = "haiku")))]
         sun_family: 0_u16,
-        #[cfg(any(
-            target_os = "dragonfly",
-            target_os = "freebsd",
-            target_os = "ios",
-            target_os = "macos",
-            target_os = "netbsd",
-            target_os = "openbsd",
-        ))]
+        #[cfg(bsd)]
         sun_path: [0; 104],
-        #[cfg(not(any(
-            target_os = "dragonfly",
-            target_os = "freebsd",
-            target_os = "haiku",
-            target_os = "ios",
-            target_os = "macos",
-            target_os = "netbsd",
-            target_os = "openbsd",
-        )))]
+        #[cfg(not(any(bsd, target_os = "haiku")))]
         sun_path: [0; 108],
         #[cfg(target_os = "haiku")]
         sun_path: [0; 126],