From a1a1f1746d156bbc9954f29134b20ed4ce2752f1 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 23 Oct 2017 14:30:29 +0200 Subject: [PATCH] unix: unify TimespecToNsec and TimevalToNsec All implementations of these functions are identical. Follow CL 30819 which did the same for syscall. Change-Id: I3c78f05ea12251306f3e100a006d266154a5238e Reviewed-on: https://go-review.googlesource.com/72378 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- unix/syscall.go | 2 -- unix/syscall_darwin_386.go | 2 -- unix/syscall_darwin_amd64.go | 2 -- unix/syscall_darwin_arm.go | 2 -- unix/syscall_darwin_arm64.go | 2 -- unix/syscall_dragonfly_amd64.go | 2 -- unix/syscall_freebsd_386.go | 2 -- unix/syscall_freebsd_amd64.go | 2 -- unix/syscall_freebsd_arm.go | 2 -- unix/syscall_linux_386.go | 2 -- unix/syscall_linux_amd64.go | 2 -- unix/syscall_linux_arm.go | 2 -- unix/syscall_linux_arm64.go | 2 -- unix/syscall_linux_mips64x.go | 2 -- unix/syscall_linux_mipsx.go | 2 -- unix/syscall_linux_ppc64x.go | 2 -- unix/syscall_linux_s390x.go | 2 -- unix/syscall_linux_sparc64.go | 2 -- unix/syscall_netbsd_386.go | 2 -- unix/syscall_netbsd_amd64.go | 2 -- unix/syscall_netbsd_arm.go | 2 -- unix/syscall_openbsd_386.go | 2 -- unix/syscall_openbsd_amd64.go | 2 -- unix/syscall_openbsd_arm.go | 2 -- unix/syscall_solaris_amd64.go | 2 -- unix/timestruct.go | 15 +++++++++++++++ 26 files changed, 15 insertions(+), 50 deletions(-) create mode 100644 unix/timestruct.go diff --git a/unix/syscall.go b/unix/syscall.go index 85e35020..432d257b 100644 --- a/unix/syscall.go +++ b/unix/syscall.go @@ -65,5 +65,3 @@ func (ts *Timespec) Nano() int64 { func (tv *Timeval) Nano() int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000 } - -func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } diff --git a/unix/syscall_darwin_386.go b/unix/syscall_darwin_386.go index 76634f7a..0426968b 100644 --- a/unix/syscall_darwin_386.go +++ b/unix/syscall_darwin_386.go @@ -11,8 +11,6 @@ import ( "unsafe" ) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int32(nsec / 1e9) ts.Nsec = int32(nsec % 1e9) diff --git a/unix/syscall_darwin_amd64.go b/unix/syscall_darwin_amd64.go index 7be02dab..f8c6dde6 100644 --- a/unix/syscall_darwin_amd64.go +++ b/unix/syscall_darwin_amd64.go @@ -11,8 +11,6 @@ import ( "unsafe" ) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = nsec % 1e9 diff --git a/unix/syscall_darwin_arm.go b/unix/syscall_darwin_arm.go index 26b66972..5f68319f 100644 --- a/unix/syscall_darwin_arm.go +++ b/unix/syscall_darwin_arm.go @@ -9,8 +9,6 @@ import ( "unsafe" ) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int32(nsec / 1e9) ts.Nsec = int32(nsec % 1e9) diff --git a/unix/syscall_darwin_arm64.go b/unix/syscall_darwin_arm64.go index 4d67a874..ca81410f 100644 --- a/unix/syscall_darwin_arm64.go +++ b/unix/syscall_darwin_arm64.go @@ -11,8 +11,6 @@ import ( "unsafe" ) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = nsec % 1e9 diff --git a/unix/syscall_dragonfly_amd64.go b/unix/syscall_dragonfly_amd64.go index 6d8952d5..6f224fd4 100644 --- a/unix/syscall_dragonfly_amd64.go +++ b/unix/syscall_dragonfly_amd64.go @@ -11,8 +11,6 @@ import ( "unsafe" ) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = nsec % 1e9 diff --git a/unix/syscall_freebsd_386.go b/unix/syscall_freebsd_386.go index 4cf5f453..5c373ab4 100644 --- a/unix/syscall_freebsd_386.go +++ b/unix/syscall_freebsd_386.go @@ -11,8 +11,6 @@ import ( "unsafe" ) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int32(nsec / 1e9) ts.Nsec = int32(nsec % 1e9) diff --git a/unix/syscall_freebsd_amd64.go b/unix/syscall_freebsd_amd64.go index b8036e72..b511dbe8 100644 --- a/unix/syscall_freebsd_amd64.go +++ b/unix/syscall_freebsd_amd64.go @@ -11,8 +11,6 @@ import ( "unsafe" ) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = nsec % 1e9 diff --git a/unix/syscall_freebsd_arm.go b/unix/syscall_freebsd_arm.go index 5a3bb6a1..6e25394d 100644 --- a/unix/syscall_freebsd_arm.go +++ b/unix/syscall_freebsd_arm.go @@ -11,8 +11,6 @@ import ( "unsafe" ) -func TimespecToNsec(ts Timespec) int64 { return ts.Sec*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = int32(nsec % 1e9) diff --git a/unix/syscall_linux_386.go b/unix/syscall_linux_386.go index f4c826a4..ba32033e 100644 --- a/unix/syscall_linux_386.go +++ b/unix/syscall_linux_386.go @@ -14,8 +14,6 @@ import ( "unsafe" ) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int32(nsec / 1e9) ts.Nsec = int32(nsec % 1e9) diff --git a/unix/syscall_linux_amd64.go b/unix/syscall_linux_amd64.go index 0715200d..13ca1322 100644 --- a/unix/syscall_linux_amd64.go +++ b/unix/syscall_linux_amd64.go @@ -83,8 +83,6 @@ func Time(t *Time_t) (tt Time_t, err error) { //sys Utime(path string, buf *Utimbuf) (err error) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = nsec % 1e9 diff --git a/unix/syscall_linux_arm.go b/unix/syscall_linux_arm.go index 2b79c84a..c5e4b88a 100644 --- a/unix/syscall_linux_arm.go +++ b/unix/syscall_linux_arm.go @@ -11,8 +11,6 @@ import ( "unsafe" ) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int32(nsec / 1e9) ts.Nsec = int32(nsec % 1e9) diff --git a/unix/syscall_linux_arm64.go b/unix/syscall_linux_arm64.go index e16a0d14..df961fed 100644 --- a/unix/syscall_linux_arm64.go +++ b/unix/syscall_linux_arm64.go @@ -73,8 +73,6 @@ func Lstat(path string, stat *Stat_t) (err error) { //sysnb Gettimeofday(tv *Timeval) (err error) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = nsec % 1e9 diff --git a/unix/syscall_linux_mips64x.go b/unix/syscall_linux_mips64x.go index 92e620ea..438fd369 100644 --- a/unix/syscall_linux_mips64x.go +++ b/unix/syscall_linux_mips64x.go @@ -76,8 +76,6 @@ func Time(t *Time_t) (tt Time_t, err error) { //sys Utime(path string, buf *Utimbuf) (err error) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = nsec % 1e9 diff --git a/unix/syscall_linux_mipsx.go b/unix/syscall_linux_mipsx.go index 25a5a0da..0e9f333c 100644 --- a/unix/syscall_linux_mipsx.go +++ b/unix/syscall_linux_mipsx.go @@ -99,8 +99,6 @@ func Seek(fd int, offset int64, whence int) (off int64, err error) { return } -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int32(nsec / 1e9) ts.Nsec = int32(nsec % 1e9) diff --git a/unix/syscall_linux_ppc64x.go b/unix/syscall_linux_ppc64x.go index a4a8e4ee..25f78f93 100644 --- a/unix/syscall_linux_ppc64x.go +++ b/unix/syscall_linux_ppc64x.go @@ -66,8 +66,6 @@ package unix //sys Utime(path string, buf *Utimbuf) (err error) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = nsec % 1e9 diff --git a/unix/syscall_linux_s390x.go b/unix/syscall_linux_s390x.go index 3845fc9c..2eb923da 100644 --- a/unix/syscall_linux_s390x.go +++ b/unix/syscall_linux_s390x.go @@ -62,8 +62,6 @@ func Time(t *Time_t) (tt Time_t, err error) { //sys Utime(path string, buf *Utimbuf) (err error) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = nsec % 1e9 diff --git a/unix/syscall_linux_sparc64.go b/unix/syscall_linux_sparc64.go index bd9de3e9..d16b7e59 100644 --- a/unix/syscall_linux_sparc64.go +++ b/unix/syscall_linux_sparc64.go @@ -82,8 +82,6 @@ func Time(t *Time_t) (tt Time_t, err error) { //sys Utime(path string, buf *Utimbuf) (err error) -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = nsec % 1e9 diff --git a/unix/syscall_netbsd_386.go b/unix/syscall_netbsd_386.go index baefa411..08e12c34 100644 --- a/unix/syscall_netbsd_386.go +++ b/unix/syscall_netbsd_386.go @@ -6,8 +6,6 @@ package unix -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int64(nsec / 1e9) ts.Nsec = int32(nsec % 1e9) diff --git a/unix/syscall_netbsd_amd64.go b/unix/syscall_netbsd_amd64.go index 59c2ab7e..2a3a6731 100644 --- a/unix/syscall_netbsd_amd64.go +++ b/unix/syscall_netbsd_amd64.go @@ -6,8 +6,6 @@ package unix -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int64(nsec / 1e9) ts.Nsec = int64(nsec % 1e9) diff --git a/unix/syscall_netbsd_arm.go b/unix/syscall_netbsd_arm.go index 7208108a..1d73b60e 100644 --- a/unix/syscall_netbsd_arm.go +++ b/unix/syscall_netbsd_arm.go @@ -6,8 +6,6 @@ package unix -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int64(nsec / 1e9) ts.Nsec = int32(nsec % 1e9) diff --git a/unix/syscall_openbsd_386.go b/unix/syscall_openbsd_386.go index d3809b42..82d057ca 100644 --- a/unix/syscall_openbsd_386.go +++ b/unix/syscall_openbsd_386.go @@ -6,8 +6,6 @@ package unix -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int64(nsec / 1e9) ts.Nsec = int32(nsec % 1e9) diff --git a/unix/syscall_openbsd_amd64.go b/unix/syscall_openbsd_amd64.go index 9a9dfcef..3518cab8 100644 --- a/unix/syscall_openbsd_amd64.go +++ b/unix/syscall_openbsd_amd64.go @@ -6,8 +6,6 @@ package unix -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = nsec % 1e9 diff --git a/unix/syscall_openbsd_arm.go b/unix/syscall_openbsd_arm.go index ba864905..ea9db8cd 100644 --- a/unix/syscall_openbsd_arm.go +++ b/unix/syscall_openbsd_arm.go @@ -6,8 +6,6 @@ package unix -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = int64(nsec / 1e9) ts.Nsec = int32(nsec % 1e9) diff --git a/unix/syscall_solaris_amd64.go b/unix/syscall_solaris_amd64.go index 5aff62c3..aeae979e 100644 --- a/unix/syscall_solaris_amd64.go +++ b/unix/syscall_solaris_amd64.go @@ -6,8 +6,6 @@ package unix -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } - func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = nsec % 1e9 diff --git a/unix/timestruct.go b/unix/timestruct.go new file mode 100644 index 00000000..3e218f6e --- /dev/null +++ b/unix/timestruct.go @@ -0,0 +1,15 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin dragonfly freebsd linux netbsd openbsd solaris + +package unix + +// TimespecToNsec converts a Timespec value into a number of +// nanoseconds since the Unix epoch. +func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } + +// TimevalToNsec converts a Timeval value into a number of nanoseconds +// since the Unix epoch. +func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }