Skip to content

Commit b2740e2

Browse files
committed
Add <sys/timex.h> declarations for Linux
1 parent 2fe7865 commit b2740e2

File tree

2 files changed

+158
-1
lines changed

2 files changed

+158
-1
lines changed

libc-test/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,9 @@ fn test_linux(target: &str) {
25172517
"sched_ss_max_repl",
25182518
].contains(&field) && musl) ||
25192519
// FIXME: After musl 1.1.24, the type becomes `int` instead of `unsigned short`.
2520-
(struct_ == "ipc_perm" && field == "__seq" && aarch64_musl)
2520+
(struct_ == "ipc_perm" && field == "__seq" && aarch64_musl) ||
2521+
// glibc uses unnamed fields here and Rust doesn't support that yet
2522+
(struct_ == "timex" && field.starts_with("__unused"))
25212523
});
25222524

25232525
cfg.skip_roundtrip(move |s| match s {

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

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,96 @@ s! {
183183
pub rt_window: ::c_ulong,
184184
pub rt_irtt: ::c_ushort,
185185
}
186+
187+
pub struct timex {
188+
pub modes: ::c_uint,
189+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
190+
pub offset: i64,
191+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
192+
pub offset: ::c_long,
193+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
194+
pub freq: i64,
195+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
196+
pub freq: ::c_long,
197+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
198+
pub maxerror: i64,
199+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
200+
pub maxerror: ::c_long,
201+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
202+
pub esterror: i64,
203+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
204+
pub esterror: ::c_long,
205+
pub status: ::c_int,
206+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
207+
pub constant: i64,
208+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
209+
pub constant: ::c_long,
210+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
211+
pub precision: i64,
212+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
213+
pub precision: ::c_long,
214+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
215+
pub tolerance: i64,
216+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
217+
pub tolerance: ::c_long,
218+
pub time: ::timeval,
219+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
220+
pub tick: i64,
221+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
222+
pub tick: ::c_long,
223+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
224+
pub ppsfreq: i64,
225+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
226+
pub ppsfreq: ::c_long,
227+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
228+
pub jitter: i64,
229+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
230+
pub jitter: ::c_long,
231+
pub shift: ::c_int,
232+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
233+
pub stabil: i64,
234+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
235+
pub stabil: ::c_long,
236+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
237+
pub jitcnt: i64,
238+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
239+
pub jitcnt: ::c_long,
240+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
241+
pub calcnt: i64,
242+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
243+
pub calcnt: ::c_long,
244+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
245+
pub errcnt: i64,
246+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
247+
pub errcnt: ::c_long,
248+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
249+
pub stbcnt: i64,
250+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
251+
pub stbcnt: ::c_long,
252+
pub tai: ::c_int,
253+
pub __unused1: i32,
254+
pub __unused2: i32,
255+
pub __unused3: i32,
256+
pub __unused4: i32,
257+
pub __unused5: i32,
258+
pub __unused6: i32,
259+
pub __unused7: i32,
260+
pub __unused8: i32,
261+
pub __unused9: i32,
262+
pub __unused10: i32,
263+
pub __unused11: i32,
264+
}
265+
266+
pub struct ntptimeval {
267+
pub time: ::timeval,
268+
pub maxerror: ::c_long,
269+
pub esterror: ::c_long,
270+
pub tai: ::c_long,
271+
pub __glibc_reserved1: ::c_long,
272+
pub __glibc_reserved2: ::c_long,
273+
pub __glibc_reserved3: ::c_long,
274+
pub __glibc_reserved4: ::c_long,
275+
}
186276
}
187277

188278
impl siginfo_t {
@@ -902,6 +992,65 @@ pub const AT_HWCAP2: ::c_ulong = 26;
902992

903993
pub const AT_EXECFN: ::c_ulong = 31;
904994

995+
//sys/timex.h
996+
pub const ADJ_OFFSET: ::c_uint = 0x0001;
997+
pub const ADJ_FREQUENCY: ::c_uint = 0x0002;
998+
pub const ADJ_MAXERROR: ::c_uint = 0x0004;
999+
pub const ADJ_ESTERROR: ::c_uint = 0x0008;
1000+
pub const ADJ_STATUS: ::c_uint = 0x0010;
1001+
pub const ADJ_TIMECONST: ::c_uint = 0x0020;
1002+
pub const ADJ_TAI: ::c_uint = 0x0080;
1003+
pub const ADJ_SETOFFSET: ::c_uint = 0x0100;
1004+
pub const ADJ_MICRO: ::c_uint = 0x1000;
1005+
pub const ADJ_NANO: ::c_uint = 0x2000;
1006+
pub const ADJ_TICK: ::c_uint = 0x4000;
1007+
pub const ADJ_OFFSET_SINGLESHOT: ::c_uint = 0x8001;
1008+
pub const ADJ_OFFSET_SS_READ: ::c_uint = 0xa001;
1009+
pub const MOD_OFFSET: ::c_uint = ADJ_OFFSET;
1010+
pub const MOD_FREQUENCY: ::c_uint = ADJ_FREQUENCY;
1011+
pub const MOD_MAXERROR: ::c_uint = ADJ_MAXERROR;
1012+
pub const MOD_ESTERROR: ::c_uint = ADJ_ESTERROR;
1013+
pub const MOD_STATUS: ::c_uint = ADJ_STATUS;
1014+
pub const MOD_TIMECONST: ::c_uint = ADJ_TIMECONST;
1015+
pub const MOD_CLKB: ::c_uint = ADJ_TICK;
1016+
pub const MOD_CLKA: ::c_uint = ADJ_OFFSET_SINGLESHOT;
1017+
pub const MOD_TAI: ::c_uint = ADJ_TAI;
1018+
pub const MOD_MICRO: ::c_uint = ADJ_MICRO;
1019+
pub const MOD_NANO: ::c_uint = ADJ_NANO;
1020+
pub const STA_PLL: ::c_int = 0x0001;
1021+
pub const STA_PPSFREQ: ::c_int = 0x0002;
1022+
pub const STA_PPSTIME: ::c_int = 0x0004;
1023+
pub const STA_FLL: ::c_int = 0x0008;
1024+
pub const STA_INS: ::c_int = 0x0010;
1025+
pub const STA_DEL: ::c_int = 0x0020;
1026+
pub const STA_UNSYNC: ::c_int = 0x0040;
1027+
pub const STA_FREQHOLD: ::c_int = 0x0080;
1028+
pub const STA_PPSSIGNAL: ::c_int = 0x0100;
1029+
pub const STA_PPSJITTER: ::c_int = 0x0200;
1030+
pub const STA_PPSWANDER: ::c_int = 0x0400;
1031+
pub const STA_PPSERROR: ::c_int = 0x0800;
1032+
pub const STA_CLOCKERR: ::c_int = 0x1000;
1033+
pub const STA_NANO: ::c_int = 0x2000;
1034+
pub const STA_MODE: ::c_int = 0x4000;
1035+
pub const STA_CLK: ::c_int = 0x8000;
1036+
pub const STA_RONLY: ::c_int = STA_PPSSIGNAL
1037+
| STA_PPSJITTER
1038+
| STA_PPSWANDER
1039+
| STA_PPSERROR
1040+
| STA_CLOCKERR
1041+
| STA_NANO
1042+
| STA_MODE
1043+
| STA_CLK;
1044+
pub const NTP_API: ::c_int = 4;
1045+
pub const TIME_OK: ::c_int = 0;
1046+
pub const TIME_INS: ::c_int = 1;
1047+
pub const TIME_DEL: ::c_int = 2;
1048+
pub const TIME_OOP: ::c_int = 3;
1049+
pub const TIME_WAIT: ::c_int = 4;
1050+
pub const TIME_ERROR: ::c_int = 5;
1051+
pub const TIME_BAD: ::c_int = TIME_ERROR;
1052+
pub const MAXTC: ::c_long = 6;
1053+
9051054
cfg_if! {
9061055
if #[cfg(any(
9071056
target_arch = "arm",
@@ -1001,13 +1150,19 @@ extern "C" {
10011150
buflen: ::size_t,
10021151
flags: ::c_uint,
10031152
) -> ::ssize_t;
1153+
10041154
pub fn memmem(
10051155
haystack: *const ::c_void,
10061156
haystacklen: ::size_t,
10071157
needle: *const ::c_void,
10081158
needlelen: ::size_t,
10091159
) -> *mut ::c_void;
10101160
pub fn getauxval(type_: ::c_ulong) -> ::c_ulong;
1161+
1162+
pub fn adjtimex(buf: *mut timex) -> ::c_int;
1163+
pub fn ntp_adjtime(buf: *mut timex) -> ::c_int;
1164+
#[link_name = "ntp_gettimex"]
1165+
pub fn ntp_gettime(buf: *mut ntptimeval) -> ::c_int;
10111166
}
10121167

10131168
#[link(name = "util")]

0 commit comments

Comments
 (0)