From a3e22011602c0f13d59e6996b0eca6be61356266 Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Wed, 21 Aug 2024 14:48:31 -0400 Subject: [PATCH] Linux: add `getitimer()`/`setitimer()` --- libc-test/build.rs | 3 +++ libc-test/semver/linux.txt | 3 +++ src/unix/linux_like/linux/mod.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 88b37451150be..bd39db5baaddb 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3598,6 +3598,9 @@ fn test_linux(target: &str) { // https://github.com/rust-lang/libc/issues/1359 "sighandler_t" => true, + // musl doesn't define these; instead, it uses a raw int for getitimer/setitimer + "__itimer_which_t" if musl => true, + // These cannot be tested when "resolv.h" is included and are tested // in the `linux_elf.rs` file. "Elf64_Phdr" | "Elf32_Phdr" => true, diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 2e928030486d4..112712921a55a 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -3478,6 +3478,7 @@ __c_anonymous_sockaddr_can_j1939 __c_anonymous_sockaddr_can_tp __errno_location __exit_status +__itimer_which_t __s16 __s32 __u16 @@ -3594,6 +3595,7 @@ getgrnam_r getgrouplist gethostid getifaddrs +getitimer getline getmntent getnameinfo @@ -3895,6 +3897,7 @@ setfsuid setgrent setgroups sethostname +setitimer setmntent setns setpriority diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index a47d0618ab230..2bfa4006127b3 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -73,6 +73,14 @@ missing! { pub enum fpos64_t {} // FIXME: fill this out with a struct } +cfg_if! { + if #[cfg(target_env = "musl")] { + pub type __itimer_which_t = ::c_int; + } else { + pub type __itimer_which_t = ::c_uint; + } +} + e! { pub enum tpacket_versions { TPACKET_V1, @@ -6116,6 +6124,28 @@ extern "C" { pub fn ioctl(fd: ::c_int, request: ::Ioctl, ...) -> ::c_int; } +cfg_if! { + if #[cfg(target_env = "musl")] { + extern "C" { + pub fn getitimer(which: ::c_int, value: *mut ::itimerval) -> ::c_int; + pub fn setitimer( + which: ::c_int, + new: *const ::itimerval, + old: *mut ::itimerval, + ) -> ::c_int; + } + } else { + extern "C" { + pub fn getitimer(which: ::__itimer_which_t, value: *mut ::itimerval) -> ::c_int; + pub fn setitimer( + which: ::__itimer_which_t, + new: *const ::itimerval, + old: *mut ::itimerval, + ) -> ::c_int; + } + } +} + // LFS64 extensions // // * musl has 64-bit versions only so aliases the LFS64 symbols to the standard ones