Use libc's syscall() and NR_GETENTROPY const

This commit is contained in:
Michael McConville 2015-12-18 22:40:07 -05:00
parent 314062b701
commit 9fde3e9b94

View file

@ -204,12 +204,6 @@ pub struct OsRng {
_dummy: (),
}
extern "C" {
fn syscall(number: c_long, ...) -> c_long;
}
const NR_GETENTROPY: c_long = 7;
impl OsRng {
/// Create a new `OsRng`.
pub fn new() -> io::Result<OsRng> {
@ -232,7 +226,7 @@ fn fill_bytes(&mut self, v: &mut [u8]) {
// getentropy(2) permits a maximum buffer size of 256 bytes
for s in v.chunks_mut(256) {
let ret = unsafe {
syscall(NR_GETENTROPY, s.as_mut_ptr(), s.len())
libc::syscall(libc::NR_GETENTROPY, s.as_mut_ptr(), s.len())
};
if ret == -1 {
panic!("unexpected getentropy error: {}", errno());