Skip to content

Commit

Permalink
Auto merge of #1982 - Thomasdezeeuw:freebsd-getrandom, r=JohnTitor
Browse files Browse the repository at this point in the history
Add getrandom to FreeBSD

Introduced in FreeBSD 12.0.

Manual page: https://www.freebsd.org/cgi/man.cgi?query=getrandom.

Not sure if the constants should be `c_int`, just matching the `flags` argument in the function, in c they're macros.
  • Loading branch information
bors committed Nov 27, 2020
2 parents e5b7d9f + 99b3635 commit 8e62c98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,7 @@ fn test_freebsd(target: &str) {
"sys/msg.h",
"sys/procdesc.h",
"sys/ptrace.h",
"sys/random.h",
"sys/resource.h",
"sys/rtprio.h",
"sys/shm.h",
Expand Down
10 changes: 10 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,16 @@ pub const F_SEAL_SHRINK: ::c_int = 0x0002;
pub const F_SEAL_GROW: ::c_int = 0x0004;
pub const F_SEAL_WRITE: ::c_int = 0x0008;

pub const GRND_NONBLOCK: ::c_uint = 0x1;
pub const GRND_RANDOM: ::c_uint = 0x2;

cfg_if! {
if #[cfg(not(freebsd13))] {
pub const ELAST: ::c_int = 96;
} else {
pub const EINTEGRITY: ::c_int = 97;
pub const ELAST: ::c_int = 97;
pub const GRND_INSECURE: ::c_uint = 0x4;
}
}

Expand All @@ -229,6 +233,12 @@ extern "C" {
) -> ::c_int;

pub fn fdatasync(fd: ::c_int) -> ::c_int;

pub fn getrandom(
buf: *mut ::c_void,
buflen: ::size_t,
flags: ::c_uint
) -> ::ssize_t;
}

cfg_if! {
Expand Down

0 comments on commit 8e62c98

Please sign in to comment.