Skip to content

Commit

Permalink
ifconf addition to apple. fixing freebsd's implementation while at it.
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Oct 13, 2023
1 parent 1bb3be5 commit 79d1b56
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions libc-test/build.rs
Expand Up @@ -374,6 +374,7 @@ fn test_apple(target: &str) {
("vnode_info_path", "vip_path") => true,
("ifreq", "ifr_ifru") => true,
("ifkpi", "ifk_data") => true,
("ifconf", "ifc_ifcu") => true,
_ => false,
}
});
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/apple.txt
Expand Up @@ -1957,6 +1957,7 @@ if_freenameindex
if_msghdr
if_nameindex
ifaddrs
ifconf
ifkpi
ifreq
image_offset
Expand Down
46 changes: 46 additions & 0 deletions src/unix/bsd/apple/mod.rs
Expand Up @@ -1129,6 +1129,15 @@ s! {
pub validattr: attribute_set_t,
pub nativeattr: attribute_set_t,
}

#[cfg_attr(libc_packedN, repr(packed(4)))]
pub struct ifconf {
pub ifc_len: ::c_int,
#[cfg(libc_union)]
pub ifc_ifcu: __c_anonymous_ifc_ifcu,
#[cfg(not(libc_union))]
pub ifc_ifcu: *mut ifreq,
}
}

s_no_extra_traits! {
Expand Down Expand Up @@ -1467,6 +1476,12 @@ s_no_extra_traits! {
#[cfg(not(libc_union))]
pub ifr_ifru: ::sockaddr,
}

#[cfg(libc_union)]
pub union __c_anonymous_ifc_ifcu {
pub ifcu_buf: *mut ::c_char,
pub ifcu_req: *mut ifreq,
}
}

impl siginfo_t {
Expand Down Expand Up @@ -3000,6 +3015,37 @@ cfg_if! {
self.ifr_ifru.hash(state);
}
}

#[cfg(libc_union)]
impl Eq for __c_anonymous_ifc_ifcu {}

#[cfg(libc_union)]
impl PartialEq for __c_anonymous_ifc_ifcu {
fn eq(&self, other: &__c_anonymous_ifc_ifcu) -> bool {
unsafe {
self.ifcu_buf == other.ifcu_buf &&
self.ifcu_req == other.ifcu_req
}
}
}

#[cfg(libc_union)]
impl ::fmt::Debug for __c_anonymous_ifc_ifcu {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("ifc_ifcu")
.field("ifcu_buf", unsafe { &self.ifcu_buf })
.field("ifcu_req", unsafe { &self.ifcu_req })
.finish()
}
}

#[cfg(libc_union)]
impl ::hash::Hash for __c_anonymous_ifc_ifcu {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
unsafe { self.ifcu_buf.hash(state) };
unsafe { self.ifcu_req.hash(state) };
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Expand Up @@ -967,6 +967,8 @@ s! {
pub ifc_len: ::c_int,
#[cfg(libc_union)]
pub ifc_ifcu: __c_anonymous_ifc_ifcu,
#[cfg(not(libc_union))]
pub ifc_ifcu: *mut ifreq,
}

pub struct au_mask_t {
Expand Down

0 comments on commit 79d1b56

Please sign in to comment.