File tree 3 files changed +13
-11
lines changed
library/std/src/sys/random
3 files changed +13
-11
lines changed Original file line number Diff line number Diff line change
1
+ pub fn fill_bytes ( mut bytes : & mut [ u8 ] ) {
2
+ while !bytes. is_empty ( ) {
3
+ let ret =
4
+ unsafe { libc:: getrandom ( bytes. as_mut_ptr ( ) . cast ( ) , bytes. len ( ) , libc:: GRND_NONBLOCK ) } ;
5
+ assert ! ( ret != -1 , "failed to generate random data" ) ;
6
+ bytes = & mut bytes[ ret as usize ..] ;
7
+ }
8
+ }
Original file line number Diff line number Diff line change @@ -94,14 +94,7 @@ fn getrandom(mut bytes: &mut [u8], insecure: bool) {
94
94
95
95
let flags = if insecure {
96
96
if GRND_INSECURE_AVAILABLE . load ( Relaxed ) {
97
- #[ cfg( target_os = "cygwin" ) ]
98
- {
99
- libc:: GRND_NONBLOCK
100
- }
101
- #[ cfg( not( target_os = "cygwin" ) ) ]
102
- {
103
- libc:: GRND_INSECURE
104
- }
97
+ libc:: GRND_INSECURE
105
98
} else {
106
99
libc:: GRND_NONBLOCK
107
100
}
@@ -117,7 +110,6 @@ fn getrandom(mut bytes: &mut [u8], insecure: bool) {
117
110
libc:: EINTR => continue ,
118
111
// `GRND_INSECURE` is not available, try
119
112
// `GRND_NONBLOCK`.
120
- #[ cfg( not( target_os = "cygwin" ) ) ]
121
113
libc:: EINVAL if flags == libc:: GRND_INSECURE => {
122
114
GRND_INSECURE_AVAILABLE . store ( false , Relaxed ) ;
123
115
continue ;
Original file line number Diff line number Diff line change 1
1
cfg_if:: cfg_if! {
2
2
// Tier 1
3
- if #[ cfg( any( target_os = "linux" , target_os = "android" , target_os = "cygwin" ) ) ] {
3
+ if #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ] {
4
4
mod linux;
5
5
pub use linux:: { fill_bytes, hashmap_random_keys} ;
6
6
} else if #[ cfg( target_os = "windows" ) ] {
7
7
mod windows;
8
8
pub use windows:: fill_bytes;
9
+ } else if #[ cfg( target_os = "cygwin" ) ] {
10
+ mod cygwin;
11
+ pub use cygwin:: fill_bytes;
9
12
} else if #[ cfg( target_vendor = "apple" ) ] {
10
13
mod apple;
11
14
pub use apple:: fill_bytes;
@@ -88,7 +91,6 @@ cfg_if::cfg_if! {
88
91
target_os = "android" ,
89
92
all( target_family = "wasm" , target_os = "unknown" ) ,
90
93
target_os = "xous" ,
91
- target_os = "cygwin" ,
92
94
) ) ) ]
93
95
pub fn hashmap_random_keys ( ) -> ( u64 , u64 ) {
94
96
let mut buf = [ 0 ; 16 ] ;
You can’t perform that action at this time.
0 commit comments