From 930f9aeedea43dfec24c27034e05a9cd5a35635e Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Wed, 6 Sep 2023 22:20:18 +0100 Subject: [PATCH] timerfd api for freebsd 14. close #3339 --- libc-test/build.rs | 8 ++++++++ src/unix/bsd/freebsdlike/freebsd/mod.rs | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index bfe1ed16f3951..c79682d1e895c 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2343,6 +2343,9 @@ fn test_freebsd(target: &str) { // Added in FreeBSD 13.2 "AT_USRSTACKBASE" | "AT_USRSTACKLIM" if Some(13) > freebsd_ver => true, + // Added in FreeBSD 14 + "TFD_CLOEXEC" | "TFD_NONBLOCK" if Some(14) > freebsd_ver => true, + _ => false, } }); @@ -2441,6 +2444,11 @@ fn test_freebsd(target: &str) { true } + // Those are introduced in FreeBSD 14. + "timerfd_create" | "timerfd_gettime" | "timerfd_settime" if Some(14) > freebsd_ver => { + true + } + _ => false, } }); diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 4138af576e936..f2236a034e06d 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -4693,6 +4693,11 @@ pub const RB_POWERCYCLE: ::c_int = 0x400000; pub const RB_PROBE: ::c_int = 0x10000000; pub const RB_MULTIPLE: ::c_int = 0x20000000; +// sys/timerfd.h + +pub const TFD_NONBLOCK: ::c_int = ::O_NONBLOCK; +pub const TFD_CLOEXEC: ::c_int = O_CLOEXEC; + cfg_if! { if #[cfg(libc_const_extern_fn)] { pub const fn MAP_ALIGNED(a: ::c_int) -> ::c_int { @@ -5406,6 +5411,15 @@ extern "C" { infotype: *mut ::c_uint, flags: *mut ::c_int, ) -> ::ssize_t; + + pub fn timerfd_create(clockid: ::c_int, flags: ::c_int) -> ::c_int; + pub fn timerfd_gettime(fd: ::c_int, curr_value: *mut itimerspec) -> ::c_int; + pub fn timerfd_settime( + fd: ::c_int, + flags: ::c_int, + new_value: *const itimerspec, + old_value: *mut itimerspec, + ) -> ::c_int; } #[link(name = "memstat")]