Skip to content

Commit f40a7c1

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

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

libc-test/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3648,6 +3648,9 @@ fn test_linux(target: &str) {
36483648
// in the `linux_elf.rs` file.
36493649
"Elf64_Phdr" | "Elf32_Phdr" => true,
36503650

3651+
// musl doesn't define these; instead, it uses a raw int for getitimer/setitimer
3652+
"__itimer_which" | "__itimer_which_t" if musl => true,
3653+
36513654
// On Linux, the type of `ut_tv` field of `struct utmpx`
36523655
// can be an anonymous struct, so an extra struct,
36533656
// which is absent in glibc, has to be defined.

libc-test/semver/linux.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,6 +3475,8 @@ __c_anonymous_sockaddr_can_j1939
34753475
__c_anonymous_sockaddr_can_tp
34763476
__errno_location
34773477
__exit_status
3478+
__itimer_which
3479+
__itimer_which_t
34783480
__s16
34793481
__s32
34803482
__u16
@@ -3591,6 +3593,7 @@ getgrnam_r
35913593
getgrouplist
35923594
gethostid
35933595
getifaddrs
3596+
getitimer
35943597
getline
35953598
getmntent
35963599
getnameinfo
@@ -3892,6 +3895,7 @@ setfsuid
38923895
setgrent
38933896
setgroups
38943897
sethostname
3898+
setitimer
38953899
setmntent
38963900
setns
38973901
setpriority

src/unix/linux_like/linux/mod.rs

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

76+
cfg_if! {
77+
if #[cfg(not(target_env = "musl"))] {
78+
pub type __itimer_which_t = ::__itimer_which;
79+
80+
e! {
81+
#[repr(i32)]
82+
pub enum __itimer_which {
83+
ITIMER_REAL = 0,
84+
ITIMER_VIRTUAL = 1,
85+
ITIMER_PROF = 2,
86+
}
87+
}
88+
}
89+
}
90+
7691
e! {
7792
pub enum tpacket_versions {
7893
TPACKET_V1,
@@ -6129,6 +6144,28 @@ extern "C" {
61296144
pub fn ioctl(fd: ::c_int, request: ::Ioctl, ...) -> ::c_int;
61306145
}
61316146

6147+
cfg_if! {
6148+
if #[cfg(target_env = "musl")] {
6149+
extern "C" {
6150+
pub fn getitimer(which: ::c_int, value: *mut ::itimerval) -> ::c_int;
6151+
pub fn setitimer(
6152+
which: ::c_int,
6153+
new: *const ::itimerval,
6154+
old: *mut ::itimerval,
6155+
) -> ::c_int;
6156+
}
6157+
} else {
6158+
extern "C" {
6159+
pub fn getitimer(which: ::__itimer_which_t, value: *mut ::itimerval) -> ::c_int;
6160+
pub fn setitimer(
6161+
which: ::__itimer_which_t,
6162+
new: *const ::itimerval,
6163+
old: *mut ::itimerval,
6164+
) -> ::c_int;
6165+
}
6166+
}
6167+
}
6168+
61326169
// LFS64 extensions
61336170
//
61346171
// * musl has 64-bit versions only so aliases the LFS64 symbols to the standard ones

0 commit comments

Comments
 (0)