Skip to content

Commit

Permalink
fix netbsd
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Oct 9, 2024
1 parent ffd3508 commit e9f21a1
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/netbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,17 @@ unsafe extern "C" fn polyfill_using_kern_arand(
debug_assert_eq!(flags, 0);

static MIB: [libc::c_int; 2] = [libc::CTL_KERN, libc::KERN_ARND];
const MIB_LEN: libc::c_uint = MIB.len() as libc::c_uint;

// NetBSD will only return up to 256 bytes at a time, and
// older NetBSD kernels will fail on longer buffers.
let mut len = cmp::min(buflen, 256);

let ret = unsafe {
libc::sysctl(
MIB.as_ptr(),
MIB.len() as libc::c_uint,
buf,
&mut len,
ptr::null(),
0,
)
};
let ret = unsafe { libc::sysctl(MIB.as_ptr(), MIB_LEN, buf, &mut len, ptr::null(), 0) };
if ret == -1 {
-1
} else {
len as libc::ssize_t
libc::ssize_t::try_from(len).expect("len is bounded by 256")
}
}

Expand Down

0 comments on commit e9f21a1

Please sign in to comment.