File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -107,13 +107,24 @@ fn getrandom_inner(
107107 unsafe { libc:: syscall ( libc:: SYS_getrandom , buf, buflen, flags) as libc:: ssize_t }
108108}
109109
110+ #[ cfg( target_os = "macos" ) ]
111+ extern "C" {
112+ // Supported as of macOS 10.12+.
113+ fn getentropy ( buf : * mut u8 , size : libc:: size_t ) -> libc:: c_int ;
114+ }
110115#[ cfg( target_os = "macos" ) ]
111116fn getrandom_inner (
112117 buf : * mut libc:: c_void ,
113118 buflen : libc:: size_t ,
114- _flags : libc:: c_uint ,
119+ flags : libc:: c_uint ,
115120) -> libc:: ssize_t {
116- unsafe { libc:: getentropy ( buf, buflen) as libc:: ssize_t }
121+ unsafe {
122+ if getentropy ( buf as * mut u8 , buflen) == 0 {
123+ return buflen as libc:: ssize_t ;
124+ } else {
125+ return -1 ;
126+ }
127+ }
117128}
118129
119130#[ cfg( target_os = "windows" ) ]
You can’t perform that action at this time.
0 commit comments