Skip to content

Commit 00e8c79

Browse files
authored
Merge pull request #1642 from dfoxfranke/sys-timex
<sys/timex.h>
2 parents 7477c68 + 51f1aa4 commit 00e8c79

File tree

6 files changed

+497
-1
lines changed

6 files changed

+497
-1
lines changed

libc-test/build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ fn test_apple(target: &str) {
150150
"sys/sysctl.h",
151151
"sys/time.h",
152152
"sys/times.h",
153+
"sys/timex.h",
153154
"sys/types.h",
154155
"sys/uio.h",
155156
"sys/un.h",
@@ -706,6 +707,7 @@ fn test_solaris(target: &str) {
706707
"sys/statvfs.h",
707708
"sys/time.h",
708709
"sys/times.h",
710+
"sys/timex.h",
709711
"sys/types.h",
710712
"sys/uio.h",
711713
"sys/un.h",
@@ -819,6 +821,7 @@ fn test_netbsd(target: &str) {
819821
"sys/sysctl.h",
820822
"sys/time.h",
821823
"sys/times.h",
824+
"sys/timex.h",
822825
"sys/uio.h",
823826
"sys/un.h",
824827
"sys/utsname.h",
@@ -1569,6 +1572,7 @@ fn test_freebsd(target: &str) {
15691572
"sys/sysctl.h",
15701573
"sys/time.h",
15711574
"sys/times.h",
1575+
"sys/timex.h",
15721576
"sys/types.h",
15731577
"sys/uio.h",
15741578
"sys/un.h",
@@ -2183,6 +2187,7 @@ fn test_linux(target: &str) {
21832187
"sys/time.h",
21842188
"sys/timerfd.h",
21852189
"sys/times.h",
2190+
"sys/timex.h",
21862191
"sys/types.h",
21872192
"sys/uio.h",
21882193
"sys/un.h",
@@ -2513,7 +2518,9 @@ fn test_linux(target: &str) {
25132518
"sched_ss_max_repl",
25142519
].contains(&field) && musl) ||
25152520
// FIXME: After musl 1.1.24, the type becomes `int` instead of `unsigned short`.
2516-
(struct_ == "ipc_perm" && field == "__seq" && aarch64_musl)
2521+
(struct_ == "ipc_perm" && field == "__seq" && aarch64_musl) ||
2522+
// glibc uses unnamed fields here and Rust doesn't support that yet
2523+
(struct_ == "timex" && field.starts_with("__unused"))
25172524
});
25182525

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

src/unix/bsd/apple/mod.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,34 @@ s! {
506506
pub sae_dstaddr: *const ::sockaddr, // destination address
507507
pub sae_dstaddrlen: ::socklen_t, // size of destination address
508508
}
509+
510+
pub struct timex {
511+
pub modes: ::c_uint,
512+
pub offset: ::c_long,
513+
pub freq: ::c_long,
514+
pub maxerror: ::c_long,
515+
pub esterror: ::c_long,
516+
pub status: ::c_int,
517+
pub constant: ::c_long,
518+
pub precision: ::c_long,
519+
pub tolerance: ::c_long,
520+
pub ppsfreq: ::c_long,
521+
pub jitter: ::c_long,
522+
pub shift: ::c_int,
523+
pub stabil: ::c_long,
524+
pub jitcnt: ::c_long,
525+
pub calcnt: ::c_long,
526+
pub errcnt: ::c_long,
527+
pub stbcnt: ::c_long,
528+
}
529+
530+
pub struct ntptimeval {
531+
pub time: ::timespec,
532+
pub maxerror: ::c_long,
533+
pub esterror: ::c_long,
534+
pub tai: ::c_long,
535+
pub time_state: ::c_int,
536+
}
509537
}
510538

511539
s_no_extra_traits! {
@@ -3063,6 +3091,58 @@ pub const SF_IMMUTABLE: ::c_uint = 0x00020000;
30633091
pub const SF_APPEND: ::c_uint = 0x00040000;
30643092
pub const UF_HIDDEN: ::c_uint = 0x00008000;
30653093

3094+
//<sys/timex.h>
3095+
pub const NTP_API: ::c_int = 4;
3096+
pub const MAXPHASE: ::c_long = 500000000;
3097+
pub const MAXFREQ: ::c_long = 500000;
3098+
pub const MINSEC: ::c_int = 256;
3099+
pub const MAXSEC: ::c_int = 2048;
3100+
pub const NANOSECOND: ::c_long = 1000000000;
3101+
pub const SCALE_PPM: ::c_int = 65;
3102+
pub const MAXTC: ::c_int = 10;
3103+
pub const MOD_OFFSET: ::c_uint = 0x0001;
3104+
pub const MOD_FREQUENCY: ::c_uint = 0x0002;
3105+
pub const MOD_MAXERROR: ::c_uint = 0x0004;
3106+
pub const MOD_ESTERROR: ::c_uint = 0x0008;
3107+
pub const MOD_STATUS: ::c_uint = 0x0010;
3108+
pub const MOD_TIMECONST: ::c_uint = 0x0020;
3109+
pub const MOD_PPSMAX: ::c_uint = 0x0040;
3110+
pub const MOD_TAI: ::c_uint = 0x0080;
3111+
pub const MOD_MICRO: ::c_uint = 0x1000;
3112+
pub const MOD_NANO: ::c_uint = 0x2000;
3113+
pub const MOD_CLKB: ::c_uint = 0x4000;
3114+
pub const MOD_CLKA: ::c_uint = 0x8000;
3115+
pub const STA_PLL: ::c_int = 0x0001;
3116+
pub const STA_PPSFREQ: ::c_int = 0x0002;
3117+
pub const STA_PPSTIME: ::c_int = 0x0004;
3118+
pub const STA_FLL: ::c_int = 0x0008;
3119+
pub const STA_INS: ::c_int = 0x0010;
3120+
pub const STA_DEL: ::c_int = 0x0020;
3121+
pub const STA_UNSYNC: ::c_int = 0x0040;
3122+
pub const STA_FREQHOLD: ::c_int = 0x0080;
3123+
pub const STA_PPSSIGNAL: ::c_int = 0x0100;
3124+
pub const STA_PPSJITTER: ::c_int = 0x0200;
3125+
pub const STA_PPSWANDER: ::c_int = 0x0400;
3126+
pub const STA_PPSERROR: ::c_int = 0x0800;
3127+
pub const STA_CLOCKERR: ::c_int = 0x1000;
3128+
pub const STA_NANO: ::c_int = 0x2000;
3129+
pub const STA_MODE: ::c_int = 0x4000;
3130+
pub const STA_CLK: ::c_int = 0x8000;
3131+
pub const STA_RONLY: ::c_int = STA_PPSSIGNAL
3132+
| STA_PPSJITTER
3133+
| STA_PPSWANDER
3134+
| STA_PPSERROR
3135+
| STA_CLOCKERR
3136+
| STA_NANO
3137+
| STA_MODE
3138+
| STA_CLK;
3139+
pub const TIME_OK: ::c_int = 0;
3140+
pub const TIME_INS: ::c_int = 1;
3141+
pub const TIME_DEL: ::c_int = 2;
3142+
pub const TIME_OOP: ::c_int = 3;
3143+
pub const TIME_WAIT: ::c_int = 4;
3144+
pub const TIME_ERROR: ::c_int = 5;
3145+
30663146
cfg_if! {
30673147
if #[cfg(libc_const_size_of)] {
30683148
fn __DARWIN_ALIGN32(p: usize) -> usize {
@@ -3576,6 +3656,9 @@ extern "C" {
35763656
associd: sae_associd_t,
35773657
connid: sae_connid_t,
35783658
) -> ::c_int;
3659+
3660+
pub fn ntp_adjtime(buf: *mut timex) -> ::c_int;
3661+
pub fn ntp_gettime(buf: *mut ntptimeval) -> ::c_int;
35793662
}
35803663

35813664
cfg_if! {

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,34 @@ s! {
190190
pub ar_pln: u8,
191191
pub ar_op: u16,
192192
}
193+
194+
pub struct timex {
195+
pub modes: ::c_uint,
196+
pub offset: ::c_long,
197+
pub freq: ::c_long,
198+
pub maxerror: ::c_long,
199+
pub esterror: ::c_long,
200+
pub status: ::c_int,
201+
pub constant: ::c_long,
202+
pub precision: ::c_long,
203+
pub tolerance: ::c_long,
204+
pub ppsfreq: ::c_long,
205+
pub jitter: ::c_long,
206+
pub shift: ::c_int,
207+
pub stabil: ::c_long,
208+
pub jitcnt: ::c_long,
209+
pub calcnt: ::c_long,
210+
pub errcnt: ::c_long,
211+
pub stbcnt: ::c_long,
212+
}
213+
214+
pub struct ntptimeval {
215+
pub time: ::timespec,
216+
pub maxerror: ::c_long,
217+
pub esterror: ::c_long,
218+
pub tai: ::c_long,
219+
pub time_state: ::c_int,
220+
}
193221
}
194222

195223
s_no_extra_traits! {
@@ -1101,6 +1129,58 @@ pub const SF_NOUNLINK: ::c_ulong = 0x00100000;
11011129

11021130
pub const TIMER_ABSTIME: ::c_int = 1;
11031131

1132+
//<sys/timex.h>
1133+
pub const NTP_API: ::c_int = 4;
1134+
pub const MAXPHASE: ::c_long = 500000000;
1135+
pub const MAXFREQ: ::c_long = 500000;
1136+
pub const MINSEC: ::c_int = 256;
1137+
pub const MAXSEC: ::c_int = 2048;
1138+
pub const NANOSECOND: ::c_long = 1000000000;
1139+
pub const SCALE_PPM: ::c_int = 65;
1140+
pub const MAXTC: ::c_int = 10;
1141+
pub const MOD_OFFSET: ::c_uint = 0x0001;
1142+
pub const MOD_FREQUENCY: ::c_uint = 0x0002;
1143+
pub const MOD_MAXERROR: ::c_uint = 0x0004;
1144+
pub const MOD_ESTERROR: ::c_uint = 0x0008;
1145+
pub const MOD_STATUS: ::c_uint = 0x0010;
1146+
pub const MOD_TIMECONST: ::c_uint = 0x0020;
1147+
pub const MOD_PPSMAX: ::c_uint = 0x0040;
1148+
pub const MOD_TAI: ::c_uint = 0x0080;
1149+
pub const MOD_MICRO: ::c_uint = 0x1000;
1150+
pub const MOD_NANO: ::c_uint = 0x2000;
1151+
pub const MOD_CLKB: ::c_uint = 0x4000;
1152+
pub const MOD_CLKA: ::c_uint = 0x8000;
1153+
pub const STA_PLL: ::c_int = 0x0001;
1154+
pub const STA_PPSFREQ: ::c_int = 0x0002;
1155+
pub const STA_PPSTIME: ::c_int = 0x0004;
1156+
pub const STA_FLL: ::c_int = 0x0008;
1157+
pub const STA_INS: ::c_int = 0x0010;
1158+
pub const STA_DEL: ::c_int = 0x0020;
1159+
pub const STA_UNSYNC: ::c_int = 0x0040;
1160+
pub const STA_FREQHOLD: ::c_int = 0x0080;
1161+
pub const STA_PPSSIGNAL: ::c_int = 0x0100;
1162+
pub const STA_PPSJITTER: ::c_int = 0x0200;
1163+
pub const STA_PPSWANDER: ::c_int = 0x0400;
1164+
pub const STA_PPSERROR: ::c_int = 0x0800;
1165+
pub const STA_CLOCKERR: ::c_int = 0x1000;
1166+
pub const STA_NANO: ::c_int = 0x2000;
1167+
pub const STA_MODE: ::c_int = 0x4000;
1168+
pub const STA_CLK: ::c_int = 0x8000;
1169+
pub const STA_RONLY: ::c_int = STA_PPSSIGNAL
1170+
| STA_PPSJITTER
1171+
| STA_PPSWANDER
1172+
| STA_PPSERROR
1173+
| STA_CLOCKERR
1174+
| STA_NANO
1175+
| STA_MODE
1176+
| STA_CLK;
1177+
pub const TIME_OK: ::c_int = 0;
1178+
pub const TIME_INS: ::c_int = 1;
1179+
pub const TIME_DEL: ::c_int = 2;
1180+
pub const TIME_OOP: ::c_int = 3;
1181+
pub const TIME_WAIT: ::c_int = 4;
1182+
pub const TIME_ERROR: ::c_int = 5;
1183+
11041184
f! {
11051185
pub fn WIFCONTINUED(status: ::c_int) -> bool {
11061186
status == 0x13
@@ -1433,6 +1513,9 @@ extern "C" {
14331513
times: *const ::timespec,
14341514
flag: ::c_int,
14351515
) -> ::c_int;
1516+
1517+
pub fn ntp_adjtime(buf: *mut timex) -> ::c_int;
1518+
pub fn ntp_gettime(buf: *mut ntptimeval) -> ::c_int;
14361519
}
14371520

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

src/unix/bsd/netbsdlike/netbsd/mod.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,35 @@ s! {
312312
pub ll_host: [::c_char; UT_HOSTSIZE],
313313
pub ll_time: ::time_t
314314
}
315+
316+
pub struct timex {
317+
pub modes: ::c_uint,
318+
pub offset: ::c_long,
319+
pub freq: ::c_long,
320+
pub maxerror: ::c_long,
321+
pub esterror: ::c_long,
322+
pub status: ::c_int,
323+
pub constant: ::c_long,
324+
pub precision: ::c_long,
325+
pub tolerance: ::c_long,
326+
pub ppsfreq: ::c_long,
327+
pub jitter: ::c_long,
328+
pub shift: ::c_int,
329+
pub stabil: ::c_long,
330+
pub jitcnt: ::c_long,
331+
pub calcnt: ::c_long,
332+
pub errcnt: ::c_long,
333+
pub stbcnt: ::c_long,
334+
}
335+
336+
pub struct ntptimeval {
337+
pub time: ::timespec,
338+
pub maxerror: ::c_long,
339+
pub esterror: ::c_long,
340+
pub tai: ::c_long,
341+
pub time_state: ::c_int,
342+
}
343+
315344
}
316345

317346
s_no_extra_traits! {
@@ -1233,6 +1262,58 @@ pub const BIOCSDLT: ::c_ulong = 0x80044278;
12331262
pub const BIOCGSEESENT: ::c_ulong = 0x40044276;
12341263
pub const BIOCSSEESENT: ::c_ulong = 0x80044277;
12351264

1265+
//<sys/timex.h>
1266+
pub const NTP_API: ::c_int = 4;
1267+
pub const MAXPHASE: ::c_long = 500000000;
1268+
pub const MAXFREQ: ::c_long = 500000;
1269+
pub const MINSEC: ::c_int = 256;
1270+
pub const MAXSEC: ::c_int = 2048;
1271+
pub const NANOSECOND: ::c_long = 1000000000;
1272+
pub const SCALE_PPM: ::c_int = 65;
1273+
pub const MAXTC: ::c_int = 10;
1274+
pub const MOD_OFFSET: ::c_uint = 0x0001;
1275+
pub const MOD_FREQUENCY: ::c_uint = 0x0002;
1276+
pub const MOD_MAXERROR: ::c_uint = 0x0004;
1277+
pub const MOD_ESTERROR: ::c_uint = 0x0008;
1278+
pub const MOD_STATUS: ::c_uint = 0x0010;
1279+
pub const MOD_TIMECONST: ::c_uint = 0x0020;
1280+
pub const MOD_PPSMAX: ::c_uint = 0x0040;
1281+
pub const MOD_TAI: ::c_uint = 0x0080;
1282+
pub const MOD_MICRO: ::c_uint = 0x1000;
1283+
pub const MOD_NANO: ::c_uint = 0x2000;
1284+
pub const MOD_CLKB: ::c_uint = 0x4000;
1285+
pub const MOD_CLKA: ::c_uint = 0x8000;
1286+
pub const STA_PLL: ::c_int = 0x0001;
1287+
pub const STA_PPSFREQ: ::c_int = 0x0002;
1288+
pub const STA_PPSTIME: ::c_int = 0x0004;
1289+
pub const STA_FLL: ::c_int = 0x0008;
1290+
pub const STA_INS: ::c_int = 0x0010;
1291+
pub const STA_DEL: ::c_int = 0x0020;
1292+
pub const STA_UNSYNC: ::c_int = 0x0040;
1293+
pub const STA_FREQHOLD: ::c_int = 0x0080;
1294+
pub const STA_PPSSIGNAL: ::c_int = 0x0100;
1295+
pub const STA_PPSJITTER: ::c_int = 0x0200;
1296+
pub const STA_PPSWANDER: ::c_int = 0x0400;
1297+
pub const STA_PPSERROR: ::c_int = 0x0800;
1298+
pub const STA_CLOCKERR: ::c_int = 0x1000;
1299+
pub const STA_NANO: ::c_int = 0x2000;
1300+
pub const STA_MODE: ::c_int = 0x4000;
1301+
pub const STA_CLK: ::c_int = 0x8000;
1302+
pub const STA_RONLY: ::c_int = STA_PPSSIGNAL
1303+
| STA_PPSJITTER
1304+
| STA_PPSWANDER
1305+
| STA_PPSERROR
1306+
| STA_CLOCKERR
1307+
| STA_NANO
1308+
| STA_MODE
1309+
| STA_CLK;
1310+
pub const TIME_OK: ::c_int = 0;
1311+
pub const TIME_INS: ::c_int = 1;
1312+
pub const TIME_DEL: ::c_int = 2;
1313+
pub const TIME_OOP: ::c_int = 3;
1314+
pub const TIME_WAIT: ::c_int = 4;
1315+
pub const TIME_ERROR: ::c_int = 5;
1316+
12361317
cfg_if! {
12371318
if #[cfg(any(target_arch = "sparc", target_arch = "sparc64",
12381319
target_arch = "x86", target_arch = "x86_64"))] {
@@ -1649,6 +1730,11 @@ f! {
16491730
}
16501731
}
16511732

1733+
extern "C" {
1734+
pub fn ntp_adjtime(buf: *mut timex) -> ::c_int;
1735+
pub fn ntp_gettime(buf: *mut ntptimeval) -> ::c_int;
1736+
}
1737+
16521738
#[link(name = "rt")]
16531739
extern "C" {
16541740
pub fn aio_read(aiocbp: *mut aiocb) -> ::c_int;

0 commit comments

Comments
 (0)