1
1
#![ allow( dead_code) ]
2
2
use crate :: Error ;
3
- use core:: mem:: MaybeUninit ;
4
3
5
4
cfg_if ! {
6
5
if #[ cfg( any( target_os = "netbsd" , target_os = "openbsd" , target_os = "android" ) ) ] {
@@ -46,33 +45,6 @@ pub fn last_os_error() -> Error {
46
45
}
47
46
}
48
47
49
- // Fill a buffer by repeatedly invoking a system call. The `sys_fill` function:
50
- // - should return -1 and set errno on failure
51
- // - should return the number of bytes written on success
52
- pub fn sys_fill_exact (
53
- mut buf : & mut [ MaybeUninit < u8 > ] ,
54
- sys_fill : impl Fn ( & mut [ MaybeUninit < u8 > ] ) -> libc:: ssize_t ,
55
- ) -> Result < ( ) , Error > {
56
- while !buf. is_empty ( ) {
57
- let res = sys_fill ( buf) ;
58
- match res {
59
- res if res > 0 => buf = buf. get_mut ( res as usize ..) . ok_or ( Error :: UNEXPECTED ) ?,
60
- -1 => {
61
- let err = last_os_error ( ) ;
62
- // We should try again if the call was interrupted.
63
- if err. raw_os_error ( ) != Some ( libc:: EINTR ) {
64
- return Err ( err) ;
65
- }
66
- }
67
- // Negative return codes not equal to -1 should be impossible.
68
- // EOF (ret = 0) should be impossible, as the data we are reading
69
- // should be an infinite stream of random bytes.
70
- _ => return Err ( Error :: UNEXPECTED ) ,
71
- }
72
- }
73
- Ok ( ( ) )
74
- }
75
-
76
48
/// Open a file in read-only mode.
77
49
///
78
50
/// # Panics
@@ -99,16 +71,3 @@ pub fn open_readonly(path: &[u8]) -> Result<libc::c_int, Error> {
99
71
}
100
72
}
101
73
}
102
-
103
- /// Thin wrapper around the `getrandom()` Linux system call
104
- #[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
105
- pub fn getrandom_syscall ( buf : & mut [ MaybeUninit < u8 > ] ) -> libc:: ssize_t {
106
- unsafe {
107
- libc:: syscall (
108
- libc:: SYS_getrandom ,
109
- buf. as_mut_ptr ( ) . cast :: < core:: ffi:: c_void > ( ) ,
110
- buf. len ( ) ,
111
- 0 ,
112
- ) as libc:: ssize_t
113
- }
114
- }
0 commit comments