Skip to content

Commit 50f4b67

Browse files
committed
Auto merge of #1354 - gnzlbg:gettimeofday, r=gnzlbg
[breaking change] gettimeofday 2nd argument incorrect in some targets The second argument of `gettimeofday` was a `*mut c_void` on all targets, but that type is incorrect in the following targets, where it should be a `*mut timezone` instead: On these other targets it appears that the signature of gettimeofday was incorrect (it takes a time-zone pointer instead of a void pointer): *linux+gnu: http://man7.org/linux/man-pages/man2/gettimeofday.2.html *freebsd: https://www.freebsd.org/cgi/man.cgi?query=gettimeofday&apropos=0&sektion=2&manpath=FreeBSD+11.2-stable&arch=default&format=html *openbsd: https://man.openbsd.org/gettimeofday.2 *android: https://github.com/ricardoquesada/android-ndk/blob/master/usr/include/sys/time.h *dragonfly: https://www.dragonflybsd.org/cgi/web-man?command=gettimeofday&section=2 This commit corrects the type on these targets, which is a breaking change. Due to how this API is commonly used (e.g. passing `ptr::null_mut` to the second argument), breakage should be minimal or non-existent (AFAICT only `time`, `libstd`, and `parking_lot` use this API, and they all should compile after this change). Users wanting to support both versions can just write `ptr as *mut _` instead. Closes #1338. --- On these targets, the signature of `gettimeofday` was correct (the second argument is a `void*`): * macosx: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/gettimeofday.2.html * linux+musl: http://git.musl-libc.org/cgit/musl/tree/include/sys/time.h#n11 * linux+newlib: https://chromium.googlesource.com/native_client/nacl-newlib/+/99fc6c167467b41466ec90e8260e9c49cbe3d13c/newlib/libc/include/sys/time.h#74 * netbsd: http://netbsd.gw.com/cgi-bin/man-cgi?gettimeofday+2.i386+NetBSD-8.0 * newlib: https://github.com/devkitPro/newlib/blob/devkitA64/newlib/libc/include/sys/time.h#L370 * solaris/illumos: https://illumos.org/man/3C/gettimeofday * emscripten: https://chromium.googlesource.com/external/github.com/kripken/emscripten/+/1.35.20/system/include/libc/sys/time.h#11 cc @alexcrichton
2 parents bf85aa6 + 759c837 commit 50f4b67

File tree

17 files changed

+32
-31
lines changed

17 files changed

+32
-31
lines changed

libc-test/build.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,6 @@ fn test_openbsd(target: &str) {
315315
match name {
316316
"execv" | "execve" | "execvp" | "execvpe" => true,
317317

318-
// typed 2nd arg
319-
"gettimeofday" => true,
320-
321318
// Removed in OpenBSD 6.5
322319
// https://marc.info/?l=openbsd-cvs&m=154723400730318
323320
"mincore" => true,
@@ -1113,9 +1110,8 @@ fn test_dragonflybsd(target: &str) {
11131110

11141111
"getrlimit" | "getrlimit64" | // non-int in 1st arg
11151112
"setrlimit" | "setrlimit64" | // non-int in 1st arg
1116-
"prlimit" | "prlimit64" | // non-int in 2nd arg
1117-
// typed 2nd arg on linux
1118-
"gettimeofday" => true,
1113+
"prlimit" | "prlimit64" // non-int in 2nd arg
1114+
=> true,
11191115

11201116
_ => false,
11211117
}
@@ -1461,10 +1457,6 @@ fn test_android(target: &str) {
14611457
"execvpe" |
14621458
"fexecve" => true,
14631459

1464-
// typed 2nd arg on android
1465-
// FIXME: still necessary?
1466-
"gettimeofday" => true,
1467-
14681460
// not declared in newer android toolchains
14691461
// FIXME: still necessary?
14701462
"getdtablesize" => true,
@@ -1815,9 +1807,6 @@ fn test_freebsd(target: &str) {
18151807
"execvpe" |
18161808
"fexecve" => true,
18171809

1818-
// FIXME: for some reason, our signature is wrong
1819-
"gettimeofday" => true,
1820-
18211810
// The `uname` function in freebsd is now an inline wrapper that
18221811
// delegates to another, but the symbol still exists, so don't check
18231812
// the symbol.
@@ -2701,10 +2690,6 @@ fn test_linux(target: &str) {
27012690
// FIXME: is this necessary?
27022691
"sendmmsg" | "recvmmsg" if musl => true,
27032692

2704-
// typed 2nd arg on linux
2705-
// FIXME: is this necessary?
2706-
"gettimeofday" => true,
2707-
27082693
// FIXME: is this necessary?
27092694
"dladdr" if musl => true, // const-ness only added recently
27102695

src/unix/bsd/apple/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,6 +3045,8 @@ extern {
30453045

30463046
pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int;
30473047

3048+
pub fn gettimeofday(tp: *mut ::timeval,
3049+
tz: *mut ::c_void) -> ::c_int;
30483050
pub fn getutxent() -> *mut utmpx;
30493051
pub fn getutxid(ut: *const utmpx) -> *mut utmpx;
30503052
pub fn getutxline(ut: *const utmpx) -> *mut utmpx;

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,8 @@ extern {
10951095
-> ::c_int;
10961096

10971097
pub fn daemon(nochdir: ::c_int, noclose: ::c_int) -> ::c_int;
1098-
1098+
pub fn gettimeofday(tp: *mut ::timeval,
1099+
tz: *mut ::timezone) -> ::c_int;
10991100
pub fn accept4(s: ::c_int, addr: *mut ::sockaddr,
11001101
addrlen: *mut ::socklen_t, flags: ::c_int) -> ::c_int;
11011102
pub fn aio_read(aiocbp: *mut aiocb) -> ::c_int;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,9 @@ extern {
14921492

14931493
#[link_name = "__lutimes50"]
14941494
pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int;
1495+
#[link_name = "__gettimeofday50"]
1496+
pub fn gettimeofday(tp: *mut ::timeval,
1497+
tz: *mut ::c_void) -> ::c_int;
14951498
pub fn getnameinfo(sa: *const ::sockaddr,
14961499
salen: ::socklen_t,
14971500
host: *mut ::c_char,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,8 @@ f! {
895895
}
896896

897897
extern {
898+
pub fn gettimeofday(tp: *mut ::timeval,
899+
tz: *mut ::timezone) -> ::c_int;
898900
pub fn chflags(path: *const ::c_char, flags: ::c_uint) -> ::c_int;
899901
pub fn fchflags(fd: ::c_int, flags: ::c_uint) -> ::c_int;
900902
pub fn chflagsat(fd: ::c_int, path: *const ::c_char, flags: ::c_uint,

src/unix/haiku/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,8 @@ extern {
12641264
errno: ::c_int) -> ::c_int>,
12651265
pglob: *mut ::glob_t) -> ::c_int;
12661266
pub fn globfree(pglob: *mut ::glob_t);
1267-
1267+
pub fn gettimeofday(tp: *mut ::timeval,
1268+
tz: *mut ::c_void) -> ::c_int;
12681269
pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
12691270
-> ::c_int;
12701271

src/unix/hermit/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,8 @@ extern {
981981

982982
pub fn clock_gettime(clock_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
983983

984+
pub fn gettimeofday(tp: *mut ::timeval,
985+
tz: *mut ::c_void) -> ::c_int;
984986
pub fn getpwuid_r(uid: ::uid_t, pwd: *mut passwd, buf: *mut ::c_char,
985987
buflen: ::size_t, result: *mut *mut passwd) -> ::c_int;
986988

src/unix/mod.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -849,17 +849,6 @@ extern {
849849

850850
pub fn flock(fd: ::c_int, operation: ::c_int) -> ::c_int;
851851

852-
#[cfg_attr(target_os = "netbsd", link_name = "__gettimeofday50")]
853-
#[deprecated(
854-
since="0.2.54",
855-
note=
856-
"The signature of this function is incorrect. \
857-
If you are using it, please report that in the following issue \
858-
so that we can evaluate the impact of fixing it: \
859-
https://github.com/rust-lang/libc/issues/1338"
860-
)]
861-
pub fn gettimeofday(tp: *mut ::timeval,
862-
tz: *mut ::c_void) -> ::c_int;
863852
#[cfg_attr(target_os = "netbsd", link_name = "__times13")]
864853
pub fn times(buf: *mut ::tms) -> ::clock_t;
865854

src/unix/newlib/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,8 @@ extern {
623623
pub fn fexecve(fd: ::c_int, argv: *const *const ::c_char,
624624
envp: *const *const ::c_char)
625625
-> ::c_int;
626+
pub fn gettimeofday(tp: *mut ::timeval,
627+
tz: *mut ::c_void) -> ::c_int;
626628
#[cfg_attr(target_os = "solaris", link_name = "__posix_getgrgid_r")]
627629
pub fn getgrgid_r(gid: ::gid_t,
628630
grp: *mut ::group,

src/unix/notbsd/android/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,8 @@ extern {
19241924
}
19251925

19261926
extern {
1927+
pub fn gettimeofday(tp: *mut ::timeval,
1928+
tz: *mut ::timezone) -> ::c_int;
19271929
pub fn madvise(addr: *const ::c_void, len: ::size_t, advice: ::c_int)
19281930
-> ::c_int;
19291931
pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;

src/unix/notbsd/emscripten/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,9 @@ extern {
16891689
pub fn rand() -> ::c_int;
16901690
pub fn srand(seed: ::c_uint);
16911691

1692+
pub fn gettimeofday(tp: *mut ::timeval,
1693+
tz: *mut ::c_void) -> ::c_int;
1694+
16921695
pub fn setpwent();
16931696
pub fn endpwent();
16941697
pub fn getpwent() -> *mut passwd;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ pub const SO_PEEK_OFF: ::c_int = 42;
325325
pub const SO_BUSY_POLL: ::c_int = 46;
326326

327327
extern {
328+
pub fn gettimeofday(tp: *mut ::timeval,
329+
tz: *mut ::c_void) -> ::c_int;
328330
pub fn ptrace(request: ::c_int, ...) -> ::c_long;
329331
pub fn getpriority(which: ::c_int, who: ::id_t) -> ::c_int;
330332
pub fn setpriority(which: ::c_int, who: ::id_t, prio: ::c_int) -> ::c_int;

src/unix/notbsd/linux/other/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,8 @@ extern {
918918
pub fn endutxent();
919919
pub fn getpt() -> ::c_int;
920920
pub fn mallopt(param: ::c_int, value: ::c_int) -> ::c_int;
921+
pub fn gettimeofday(tp: *mut ::timeval,
922+
tz: *mut ::timezone) -> ::c_int;
921923
}
922924

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

src/unix/notbsd/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,6 @@ extern {
12651265
pshared: ::c_int,
12661266
value: ::c_uint)
12671267
-> ::c_int;
1268-
12691268
pub fn fdatasync(fd: ::c_int) -> ::c_int;
12701269
pub fn mincore(addr: *mut ::c_void, len: ::size_t,
12711270
vec: *mut ::c_uchar) -> ::c_int;

src/unix/redox/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,5 +584,7 @@ extern {
584584
iovcnt: ::c_int) -> ::ssize_t;
585585

586586
// time.h
587+
pub fn gettimeofday(tp: *mut ::timeval,
588+
tz: *mut ::timezone) -> ::c_int;
587589
pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
588590
}

src/unix/solarish/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,8 @@ extern {
18001800
pub fn rand() -> ::c_int;
18011801
pub fn srand(seed: ::c_uint);
18021802

1803+
pub fn gettimeofday(tp: *mut ::timeval,
1804+
tz: *mut ::c_void) -> ::c_int;
18031805
pub fn getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int;
18041806
pub fn freeifaddrs(ifa: *mut ::ifaddrs);
18051807

src/unix/uclibc/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,8 @@ extern {
15001500
pub fn srand(seed: ::c_uint);
15011501

15021502
pub fn fdatasync(fd: ::c_int) -> ::c_int;
1503+
pub fn gettimeofday(tp: *mut ::timeval,
1504+
tz: *mut ::timezone) -> ::c_int;
15031505
pub fn mincore(addr: *mut ::c_void, len: ::size_t,
15041506
vec: *mut ::c_uchar) -> ::c_int;
15051507
pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;

0 commit comments

Comments
 (0)