Skip to content

Commit e71b2c2

Browse files
committed
Use libc::SYS_getrandom
Cleans up the usage of libc to use the constants for the getrandom syscall. This has been in libc for a while, so we don't need to increment the libc version in Cargo.toml.
1 parent 680570f commit e71b2c2

1 file changed

Lines changed: 2 additions & 17 deletions

File tree

src/rand.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,11 @@ use crate::sealed;
117117
#[cfg(target_os = "linux")]
118118
mod sysrand_chunk {
119119
use crate::error;
120-
use libc::{self, size_t};
120+
use libc;
121121

122122
#[inline]
123123
pub fn chunk(dest: &mut [u8]) -> Result<usize, error::Unspecified> {
124-
// See `SYS_getrandom` in #include <sys/syscall.h>.
125-
126-
#[cfg(target_arch = "aarch64")]
127-
const SYS_GETRANDOM: libc::c_long = 278;
128-
129-
#[cfg(target_arch = "arm")]
130-
const SYS_GETRANDOM: libc::c_long = 384;
131-
132-
#[cfg(target_arch = "x86")]
133-
const SYS_GETRANDOM: libc::c_long = 355;
134-
135-
#[cfg(target_arch = "x86_64")]
136-
const SYS_GETRANDOM: libc::c_long = 318;
137-
138-
let chunk_len: size_t = dest.len();
139-
let r = unsafe { libc::syscall(SYS_GETRANDOM, dest.as_mut_ptr(), chunk_len, 0) };
124+
let r = unsafe { libc::syscall(libc::SYS_getrandom, dest.as_mut_ptr(), dest.len(), 0) };
140125
if r < 0 {
141126
if unsafe { *libc::__errno_location() } == libc::EINTR {
142127
// If an interrupt occurs while getrandom() is blocking to wait

0 commit comments

Comments
 (0)