11//! Implementation for Linux / Android with `/dev/urandom` fallback
2- use crate :: { lazy:: LazyBool , linux_android, use_file, util_libc :: last_os_error , Error } ;
2+ use crate :: { lazy:: LazyBool , linux_android, use_file, Error } ;
33use core:: mem:: MaybeUninit ;
44
55pub fn getrandom_inner ( dest : & mut [ MaybeUninit < u8 > ] ) -> Result < ( ) , Error > {
@@ -13,17 +13,13 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
1313}
1414
1515fn is_getrandom_available ( ) -> bool {
16- if linux_android:: getrandom_syscall ( & mut [ ] ) < 0 {
17- match last_os_error ( ) . raw_os_error ( ) {
18- Some ( libc:: ENOSYS ) => false , // No kernel support
19- // The fallback on EPERM is intentionally not done on Android since this workaround
20- // seems to be needed only for specific Linux-based products that aren't based
21- // on Android. See https://github.com/rust-random/getrandom/issues/229.
22- #[ cfg( target_os = "linux" ) ]
23- Some ( libc:: EPERM ) => false , // Blocked by seccomp
24- _ => true ,
25- }
26- } else {
27- true
16+ match linux_android:: getrandom_syscall ( & mut [ ] ) {
17+ Err ( err) if err. raw_os_error ( ) == Some ( libc:: ENOSYS ) => false , // No kernel support
18+ // The fallback on EPERM is intentionally not done on Android since this workaround
19+ // seems to be needed only for specific Linux-based products that aren't based
20+ // on Android. See https://github.com/rust-random/getrandom/issues/229.
21+ #[ cfg( target_os = "linux" ) ]
22+ Err ( err) if err. raw_os_error ( ) == Some ( libc:: EPERM ) => false , // Blocked by seccomp
23+ _ => true ,
2824 }
2925}
0 commit comments