-
Notifications
You must be signed in to change notification settings - Fork 218
Freebsd: Try getrandom() first #57
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,36 @@ | |
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
extern crate std; | ||
|
||
use crate::util::LazyUsize; | ||
use crate::Error; | ||
use core::ptr::NonNull; | ||
use std::io; | ||
|
||
// Fill a buffer by repeatedly invoking a system call. The `sys_fill` function: | ||
// - should return -1 and set errno on failure | ||
// - should return the number of bytes written on success | ||
pub fn sys_fill_exact( | ||
mut buf: &mut [u8], | ||
sys_fill: impl Fn(&mut [u8]) -> libc::ssize_t, | ||
) -> Result<(), Error> { | ||
while !buf.is_empty() { | ||
let res = sys_fill(buf); | ||
if res < 0 { | ||
let err = io::Error::last_os_error(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems odd to me to assume that calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During removal of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I changed the function to be named |
||
// We should try again if the call was interrupted. | ||
if err.raw_os_error() != Some(libc::EINTR) { | ||
return Err(err.into()); | ||
} | ||
} else { | ||
// We don't check for EOF (ret = 0) as the data we are reading | ||
// should be an infinite stream of random bytes. | ||
buf = &mut buf[(res as usize)..]; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
// A "weak" binding to a C function that may or may not be present at runtime. | ||
// Used for supporting newer OS features while still building on older systems. | ||
|
Uh oh!
There was an error while loading. Please reload this page.