From 6c517df4daa0acaa25a16baeef5ea037c9a0194c Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 11 Oct 2016 21:04:16 -0700 Subject: syscall: unify NsecToTime{spec,val}, fix for times < 1970 All the implementations of NsecToTimespec and NsecToTimeval were the same other than types. Write a single version that uses GOARCH/GOOS-specific setTimespec and setTimeval functions to handle the types. The logic in NsecToTimespec and NsecToTimeval caused times before 1970 to have a negative usec/nsec. The Linux kernel requires that usec contain a positive number; for consistency, we do this for both NsecToTimespec and NsecToTimeval. Change-Id: I525eaba2e7cdb00cb57fa00182dabf19fec298ae Reviewed-on: https://go-review.googlesource.com/30826 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Russ Cox --- src/syscall/syscall_linux_amd64.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/syscall/syscall_linux_amd64.go') diff --git a/src/syscall/syscall_linux_amd64.go b/src/syscall/syscall_linux_amd64.go index faa973dbdf..684bd9cd05 100644 --- a/src/syscall/syscall_linux_amd64.go +++ b/src/syscall/syscall_linux_amd64.go @@ -84,17 +84,12 @@ func Time(t *Time_t) (tt Time_t, err error) { return Time_t(tv.Sec), nil } -func NsecToTimespec(nsec int64) (ts Timespec) { - ts.Sec = nsec / 1e9 - ts.Nsec = nsec % 1e9 - return +func setTimespec(sec, nsec int64) Timespec { + return Timespec{Sec: sec, Nsec: nsec} } -func NsecToTimeval(nsec int64) (tv Timeval) { - nsec += 999 // round up to microsecond - tv.Sec = nsec / 1e9 - tv.Usec = nsec % 1e9 / 1e3 - return +func setTimeval(sec, usec int64) Timeval { + return Timeval{Sec: sec, Usec: usec} } //sysnb pipe(p *[2]_C_int) (err error) -- cgit v1.3-5-g9baa