syscall: unify TimespecToNsec and TimevalToNsec

All implementations of these functions are identical.

Change-Id: I7cbea53c02bb0cee75e30beed19d29ba0a7ef657
Reviewed-on: https://go-review.googlesource.com/30819
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Ian Lance Taylor 2016-10-11 14:20:50 -07:00
parent e1fc292500
commit 7f6eadb64f
26 changed files with 11 additions and 98 deletions

View file

@ -6,16 +6,12 @@ package syscall
import "unsafe" import "unsafe"
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int32(nsec / 1e9) ts.Sec = int32(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9) ts.Nsec = int32(nsec % 1e9)
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -6,16 +6,12 @@ package syscall
import "unsafe" import "unsafe"
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = nsec / 1e9 ts.Sec = nsec / 1e9
ts.Nsec = nsec % 1e9 ts.Nsec = nsec % 1e9
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -6,16 +6,12 @@ package syscall
import "unsafe" import "unsafe"
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int32(nsec / 1e9) ts.Sec = int32(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9) ts.Nsec = int32(nsec % 1e9)
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -6,16 +6,12 @@ package syscall
import "unsafe" import "unsafe"
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = nsec / 1e9 ts.Sec = nsec / 1e9
ts.Nsec = nsec % 1e9 ts.Nsec = nsec % 1e9
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -6,16 +6,12 @@ package syscall
import "unsafe" import "unsafe"
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = nsec / 1e9 ts.Sec = nsec / 1e9
ts.Nsec = nsec % 1e9 ts.Nsec = nsec % 1e9
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = nsec % 1e9 / 1e3 tv.Usec = nsec % 1e9 / 1e3

View file

@ -6,16 +6,12 @@ package syscall
import "unsafe" import "unsafe"
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int32(nsec / 1e9) ts.Sec = int32(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9) ts.Nsec = int32(nsec % 1e9)
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -6,16 +6,12 @@ package syscall
import "unsafe" import "unsafe"
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = nsec / 1e9 ts.Sec = nsec / 1e9
ts.Nsec = nsec % 1e9 ts.Nsec = nsec % 1e9
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = nsec % 1e9 / 1e3 tv.Usec = nsec % 1e9 / 1e3

View file

@ -6,16 +6,12 @@ package syscall
import "unsafe" import "unsafe"
func TimespecToNsec(ts Timespec) int64 { return ts.Sec*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = nsec / 1e9 ts.Sec = nsec / 1e9
ts.Nsec = int32(nsec % 1e9) ts.Nsec = int32(nsec % 1e9)
return return
} }
func TimevalToNsec(tv Timeval) int64 { return tv.Sec*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -14,16 +14,12 @@ const (
_SYS_getdents = SYS_GETDENTS64 _SYS_getdents = SYS_GETDENTS64
) )
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int32(nsec / 1e9) ts.Sec = int32(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9) ts.Nsec = int32(nsec % 1e9)
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Sec = int32(nsec / 1e9) tv.Sec = int32(nsec / 1e9)

View file

@ -84,16 +84,12 @@ func Time(t *Time_t) (tt Time_t, err error) {
return Time_t(tv.Sec), nil return Time_t(tv.Sec), nil
} }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = nsec / 1e9 ts.Sec = nsec / 1e9
ts.Nsec = nsec % 1e9 ts.Nsec = nsec % 1e9
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Sec = nsec / 1e9 tv.Sec = nsec / 1e9

View file

@ -11,8 +11,6 @@ const (
_SYS_getdents = SYS_GETDENTS64 _SYS_getdents = SYS_GETDENTS64
) )
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int32(nsec / 1e9) ts.Sec = int32(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9) ts.Nsec = int32(nsec % 1e9)

View file

@ -71,16 +71,12 @@ func Lstat(path string, stat *Stat_t) (err error) {
//sysnb Gettimeofday(tv *Timeval) (err error) //sysnb Gettimeofday(tv *Timeval) (err error)
//sysnb Time(t *Time_t) (tt Time_t, err error) //sysnb Time(t *Time_t) (tt Time_t, err error)
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = nsec / 1e9 ts.Sec = nsec / 1e9
ts.Nsec = nsec % 1e9 ts.Nsec = nsec % 1e9
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Sec = nsec / 1e9 tv.Sec = nsec / 1e9

View file

@ -79,16 +79,12 @@ func Time(t *Time_t) (tt Time_t, err error) {
return Time_t(tv.Sec), nil return Time_t(tv.Sec), nil
} }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = nsec / 1e9 ts.Sec = nsec / 1e9
ts.Nsec = nsec % 1e9 ts.Nsec = nsec % 1e9
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Sec = nsec / 1e9 tv.Sec = nsec / 1e9

View file

@ -67,16 +67,12 @@ const (
//sysnb Gettimeofday(tv *Timeval) (err error) //sysnb Gettimeofday(tv *Timeval) (err error)
//sysnb Time(t *Time_t) (tt Time_t, err error) //sysnb Time(t *Time_t) (tt Time_t, err error)
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = nsec / 1e9 ts.Sec = nsec / 1e9
ts.Nsec = nsec % 1e9 ts.Nsec = nsec % 1e9
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Sec = nsec / 1e9 tv.Sec = nsec / 1e9

View file

@ -58,16 +58,12 @@ func Time(t *Time_t) (tt Time_t, err error) {
return Time_t(tv.Sec), nil return Time_t(tv.Sec), nil
} }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = nsec / 1e9 ts.Sec = nsec / 1e9
ts.Nsec = nsec % 1e9 ts.Nsec = nsec % 1e9
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Sec = nsec / 1e9 tv.Sec = nsec / 1e9

View file

@ -14,16 +14,12 @@ type Timeval struct {
Usec int32 Usec int32
} }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int64(nsec / 1e9) ts.Sec = int64(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9) ts.Nsec = int32(nsec % 1e9)
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -14,16 +14,12 @@ type Timeval struct {
Usec int32 Usec int32
} }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int64(nsec / 1e9) ts.Sec = int64(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9) ts.Nsec = int32(nsec % 1e9)
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -14,16 +14,12 @@ type Timeval struct {
Usec int32 Usec int32
} }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int64(nsec / 1e9) ts.Sec = int64(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9) ts.Nsec = int32(nsec % 1e9)
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -4,16 +4,12 @@
package syscall package syscall
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int64(nsec / 1e9) ts.Sec = int64(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9) ts.Nsec = int32(nsec % 1e9)
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -4,16 +4,12 @@
package syscall package syscall
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int64(nsec / 1e9) ts.Sec = int64(nsec / 1e9)
ts.Nsec = int64(nsec % 1e9) ts.Nsec = int64(nsec % 1e9)
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -4,16 +4,12 @@
package syscall package syscall
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int64(nsec / 1e9) ts.Sec = int64(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9) ts.Nsec = int32(nsec % 1e9)
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -4,16 +4,12 @@
package syscall package syscall
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int64(nsec / 1e9) ts.Sec = int64(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9) ts.Nsec = int32(nsec % 1e9)
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -4,16 +4,12 @@
package syscall package syscall
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = nsec / 1e9 ts.Sec = nsec / 1e9
ts.Nsec = nsec % 1e9 ts.Nsec = nsec % 1e9
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = nsec % 1e9 / 1e3 tv.Usec = nsec % 1e9 / 1e3

View file

@ -4,16 +4,12 @@
package syscall package syscall
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = int64(nsec / 1e9) ts.Sec = int64(nsec / 1e9)
ts.Nsec = int32(nsec % 1e9) ts.Nsec = int32(nsec % 1e9)
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = int32(nsec % 1e9 / 1e3) tv.Usec = int32(nsec % 1e9 / 1e3)

View file

@ -4,16 +4,12 @@
package syscall package syscall
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
ts.Sec = nsec / 1e9 ts.Sec = nsec / 1e9
ts.Nsec = nsec % 1e9 ts.Nsec = nsec % 1e9
return return
} }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
func NsecToTimeval(nsec int64) (tv Timeval) { func NsecToTimeval(nsec int64) (tv Timeval) {
nsec += 999 // round up to microsecond nsec += 999 // round up to microsecond
tv.Usec = nsec % 1e9 / 1e3 tv.Usec = nsec % 1e9 / 1e3

11
src/syscall/timestruct.go Normal file
View file

@ -0,0 +1,11 @@
// Copyright 2016 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 nacl netbsd openbsd solaris
package syscall
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }