Skip to content

Commit

Permalink
Delegate to linux_android from linux_android_with_fallback.
Browse files Browse the repository at this point in the history
Instead of duplicating the implementation of
`linux_android::getrandom_inner` inline, call
`linux_android::getrandom_inner`, like we do for
`use_file::getrandom_inner`. This way, there is no doubt that they do
exactly the same thing.
  • Loading branch information
briansmith committed Jun 6, 2024
1 parent 05cdf6f commit 45781c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ cfg_if! {
mod util_libc;
mod use_file;
mod lazy;
mod linux_android;
#[path = "linux_android_with_fallback.rs"] mod imp;
} else if #[cfg(any(target_os = "android", target_os = "linux"))] {
mod util_libc;
Expand Down
7 changes: 4 additions & 3 deletions src/linux_android_with_fallback.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
//! Implementation for Linux / Android with `/dev/urandom` fallback
use crate::{
lazy::LazyBool,
util_libc::{getrandom_syscall, last_os_error, sys_fill_exact},
{use_file, Error},
linux_android, use_file,
util_libc::{getrandom_syscall, last_os_error},
Error,
};
use core::mem::MaybeUninit;

pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
// getrandom(2) was introduced in Linux 3.17
static HAS_GETRANDOM: LazyBool = LazyBool::new();
if HAS_GETRANDOM.unsync_init(is_getrandom_available) {
sys_fill_exact(dest, getrandom_syscall)
linux_android::getrandom_inner(dest)
} else {
use_file::getrandom_inner(dest)
}
Expand Down

0 comments on commit 45781c7

Please sign in to comment.