Skip to content

Commit 8897989

Browse files
Linux: add getitimer()/setitimer()
1 parent e19650d commit 8897989

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

libc-test/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3558,6 +3558,9 @@ fn test_linux(target: &str) {
35583558
// https://github.com/rust-lang/libc/issues/1359
35593559
"sighandler_t" => true,
35603560

3561+
// musl doesn't define these; instead, it uses a raw int for getitimer/setitimer
3562+
"__itimer_which_t" if musl => true,
3563+
35613564
// These cannot be tested when "resolv.h" is included and are tested
35623565
// in the `linux_elf.rs` file.
35633566
"Elf64_Phdr" | "Elf32_Phdr" => true,

libc-test/semver/linux.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,6 +3475,7 @@ __c_anonymous_sockaddr_can_j1939
34753475
__c_anonymous_sockaddr_can_tp
34763476
__errno_location
34773477
__exit_status
3478+
__itimer_which_t
34783479
__s16
34793480
__s32
34803481
__u16
@@ -3591,6 +3592,7 @@ getgrnam_r
35913592
getgrouplist
35923593
gethostid
35933594
getifaddrs
3595+
getitimer
35943596
getline
35953597
getmntent
35963598
getnameinfo
@@ -3892,6 +3894,7 @@ setfsuid
38923894
setgrent
38933895
setgroups
38943896
sethostname
3897+
setitimer
38953898
setmntent
38963899
setns
38973900
setpriority

src/unix/linux_like/linux/mod.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,18 @@ missing! {
7373
pub enum fpos64_t {} // FIXME: fill this out with a struct
7474
}
7575

76-
e! {
77-
pub enum tpacket_versions {
78-
TPACKET_V1,
79-
TPACKET_V2,
80-
TPACKET_V3,
76+
cfg_if! {
77+
if #[cfg(target_env = "musl")] {
78+
pub type __itimer_which_t = ::c_int;
79+
} else {
80+
e! {
81+
#[repr(i32)]
82+
pub enum __itimer_which_t {
83+
ITIMER_REAL = 0,
84+
ITIMER_VIRTUAL = 1,
85+
ITIMER_PROF = 2,
86+
}
87+
}
8188
}
8289
}
8390

@@ -6129,6 +6136,28 @@ extern "C" {
61296136
pub fn ioctl(fd: ::c_int, request: ::Ioctl, ...) -> ::c_int;
61306137
}
61316138

6139+
cfg_if! {
6140+
if #[cfg(target_env = "musl")] {
6141+
extern "C" {
6142+
pub fn getitimer(which: ::c_int, value: *mut ::itimerval) -> ::c_int;
6143+
pub fn setitimer(
6144+
which: ::c_int,
6145+
new: *const ::itimerval,
6146+
old: *mut ::itimerval,
6147+
) -> ::c_int;
6148+
}
6149+
} else {
6150+
extern "C" {
6151+
pub fn getitimer(which: ::__itimer_which_t, value: *mut ::itimerval) -> ::c_int;
6152+
pub fn setitimer(
6153+
which: ::__itimer_which_t,
6154+
new: *const ::itimerval,
6155+
old: *mut ::itimerval,
6156+
) -> ::c_int;
6157+
}
6158+
}
6159+
}
6160+
61326161
// LFS64 extensions
61336162
//
61346163
// * musl has 64-bit versions only so aliases the LFS64 symbols to the standard ones

0 commit comments

Comments
 (0)