Skip to content

Commit de9c207

Browse files
committed
Auto merge of #2333 - dfoxfranke:master, r=JohnTitor
Add <sys/timex.h> bindings for linux-musl Adds bindings for `adjtimex()` & co. for linux-musl. Also adds `clock_adjtime()` to linux-glibc.
2 parents 94bf82a + 530b4ca commit de9c207

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

libc-test/semver/linux-gnu.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ __rlimit_resource_t
525525
__timeval
526526
adjtimex
527527
backtrace
528+
clock_adjtime
528529
copy_file_range
529530
dlinfo
530531
dlmopen

libc-test/semver/linux-musl.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
# TODO: musl.
2+
adjtimex
3+
clock_adjtime
24
explicit_bzero
5+
ntptimeval
36
reallocarray
7+
timex
8+

src/unix/linux_like/linux/gnu/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,8 @@ extern "C" {
12231223
pub fn ntp_adjtime(buf: *mut timex) -> ::c_int;
12241224
#[link_name = "ntp_gettimex"]
12251225
pub fn ntp_gettime(buf: *mut ntptimeval) -> ::c_int;
1226+
pub fn clock_adjtime(clk_id: ::clockid_t, buf: *mut ::timex) -> ::c_int;
1227+
12261228
pub fn copy_file_range(
12271229
fd_in: ::c_int,
12281230
off_in: *mut ::off64_t,

src/unix/linux_like/linux/musl/mod.rs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,36 @@ s! {
249249
pub ch_size: ::Elf32_Word,
250250
pub ch_addralign: ::Elf32_Word,
251251
}
252+
253+
pub struct timex {
254+
pub modes: ::c_uint,
255+
pub offset: ::c_long,
256+
pub freq: ::c_long,
257+
pub maxerror: ::c_long,
258+
pub esterror: ::c_long,
259+
pub status: ::c_int,
260+
pub constant: ::c_long,
261+
pub precision: ::c_long,
262+
pub tolerance: ::c_long,
263+
pub time: ::timeval,
264+
pub tick: ::c_long,
265+
pub ppsfreq: ::c_long,
266+
pub jitter: ::c_long,
267+
pub shift: ::c_int,
268+
pub stabil: ::c_long,
269+
pub jitcnt: ::c_long,
270+
pub calcnt: ::c_long,
271+
pub errcnt: ::c_long,
272+
pub stbcnt: ::c_long,
273+
pub tai: ::c_int,
274+
pub __padding: [::c_int; 11],
275+
}
276+
277+
pub struct ntptimeval {
278+
pub time: ::timeval,
279+
pub maxerror: ::c_long,
280+
pub esterror: ::c_long,
281+
}
252282
}
253283

254284
s_no_extra_traits! {
@@ -623,6 +653,64 @@ pub const PRIO_PROCESS: ::c_int = 0;
623653
pub const PRIO_PGRP: ::c_int = 1;
624654
pub const PRIO_USER: ::c_int = 2;
625655

656+
pub const ADJ_OFFSET: ::c_uint = 0x0001;
657+
pub const ADJ_FREQUENCY: ::c_uint = 0x0002;
658+
pub const ADJ_MAXERROR: ::c_uint = 0x0004;
659+
pub const ADJ_ESTERROR: ::c_uint = 0x0008;
660+
pub const ADJ_STATUS: ::c_uint = 0x0010;
661+
pub const ADJ_TIMECONST: ::c_uint = 0x0020;
662+
pub const ADJ_TAI: ::c_uint = 0x0080;
663+
pub const ADJ_SETOFFSET: ::c_uint = 0x0100;
664+
pub const ADJ_MICRO: ::c_uint = 0x1000;
665+
pub const ADJ_NANO: ::c_uint = 0x2000;
666+
pub const ADJ_TICK: ::c_uint = 0x4000;
667+
pub const ADJ_OFFSET_SINGLESHOT: ::c_uint = 0x8001;
668+
pub const ADJ_OFFSET_SS_READ: ::c_uint = 0xa001;
669+
pub const MOD_OFFSET: ::c_uint = ADJ_OFFSET;
670+
pub const MOD_FREQUENCY: ::c_uint = ADJ_FREQUENCY;
671+
pub const MOD_MAXERROR: ::c_uint = ADJ_MAXERROR;
672+
pub const MOD_ESTERROR: ::c_uint = ADJ_ESTERROR;
673+
pub const MOD_STATUS: ::c_uint = ADJ_STATUS;
674+
pub const MOD_TIMECONST: ::c_uint = ADJ_TIMECONST;
675+
pub const MOD_CLKB: ::c_uint = ADJ_TICK;
676+
pub const MOD_CLKA: ::c_uint = ADJ_OFFSET_SINGLESHOT;
677+
pub const MOD_TAI: ::c_uint = ADJ_TAI;
678+
pub const MOD_MICRO: ::c_uint = ADJ_MICRO;
679+
pub const MOD_NANO: ::c_uint = ADJ_NANO;
680+
pub const STA_PLL: ::c_int = 0x0001;
681+
pub const STA_PPSFREQ: ::c_int = 0x0002;
682+
pub const STA_PPSTIME: ::c_int = 0x0004;
683+
pub const STA_FLL: ::c_int = 0x0008;
684+
pub const STA_INS: ::c_int = 0x0010;
685+
pub const STA_DEL: ::c_int = 0x0020;
686+
pub const STA_UNSYNC: ::c_int = 0x0040;
687+
pub const STA_FREQHOLD: ::c_int = 0x0080;
688+
pub const STA_PPSSIGNAL: ::c_int = 0x0100;
689+
pub const STA_PPSJITTER: ::c_int = 0x0200;
690+
pub const STA_PPSWANDER: ::c_int = 0x0400;
691+
pub const STA_PPSERROR: ::c_int = 0x0800;
692+
pub const STA_CLOCKERR: ::c_int = 0x1000;
693+
pub const STA_NANO: ::c_int = 0x2000;
694+
pub const STA_MODE: ::c_int = 0x4000;
695+
pub const STA_CLK: ::c_int = 0x8000;
696+
pub const STA_RONLY: ::c_int = STA_PPSSIGNAL
697+
| STA_PPSJITTER
698+
| STA_PPSWANDER
699+
| STA_PPSERROR
700+
| STA_CLOCKERR
701+
| STA_NANO
702+
| STA_MODE
703+
| STA_CLK;
704+
705+
pub const TIME_OK: ::c_int = 0;
706+
pub const TIME_INS: ::c_int = 1;
707+
pub const TIME_DEL: ::c_int = 2;
708+
pub const TIME_OOP: ::c_int = 3;
709+
pub const TIME_WAIT: ::c_int = 4;
710+
pub const TIME_ERROR: ::c_int = 5;
711+
pub const TIME_BAD: ::c_int = TIME_ERROR;
712+
pub const MAXTC: ::c_long = 6;
713+
626714
cfg_if! {
627715
if #[cfg(target_arch = "s390x")] {
628716
pub const POSIX_FADV_DONTNEED: ::c_int = 6;
@@ -702,6 +790,9 @@ extern "C" {
702790
pub fn explicit_bzero(s: *mut ::c_void, len: ::size_t);
703791
// Added in `musl` 1.2.2
704792
pub fn reallocarray(ptr: *mut ::c_void, nmemb: ::size_t, size: ::size_t) -> *mut ::c_void;
793+
794+
pub fn adjtimex(buf: *mut ::timex) -> ::c_int;
795+
pub fn clock_adjtime(clk_id: ::clockid_t, buf: *mut ::timex) -> ::c_int;
705796
}
706797

707798
cfg_if! {

0 commit comments

Comments
 (0)