mirror of https://github.com/golang/go.git
syscall: drop references to Unix epoch in Timeval/Timespec docs
The various conversion functions just change the format of time values. They don't use the Unix epoch. Although in practice the values are often times since the Unix epoch, they aren't always, so referring to the epoch can be confusing. Fixes #43010 Change-Id: I640d665f0d2017f0974db05d70858037c7c91eda Reviewed-on: https://go-review.googlesource.com/c/go/+/277073 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
1fe891a937
commit
e012d0dc34
|
|
@ -77,24 +77,22 @@ func BytePtrFromString(s string) (*byte, error) {
|
||||||
// See mksyscall.pl.
|
// See mksyscall.pl.
|
||||||
var _zero uintptr
|
var _zero uintptr
|
||||||
|
|
||||||
// Unix returns ts as the number of seconds and nanoseconds elapsed since the
|
// Unix returns the time stored in ts as seconds plus nanoseconds.
|
||||||
// Unix epoch.
|
|
||||||
func (ts *Timespec) Unix() (sec int64, nsec int64) {
|
func (ts *Timespec) Unix() (sec int64, nsec int64) {
|
||||||
return int64(ts.Sec), int64(ts.Nsec)
|
return int64(ts.Sec), int64(ts.Nsec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unix returns tv as the number of seconds and nanoseconds elapsed since the
|
// Unix returns the time stored in tv as seconds plus nanoseconds.
|
||||||
// Unix epoch.
|
|
||||||
func (tv *Timeval) Unix() (sec int64, nsec int64) {
|
func (tv *Timeval) Unix() (sec int64, nsec int64) {
|
||||||
return int64(tv.Sec), int64(tv.Usec) * 1000
|
return int64(tv.Sec), int64(tv.Usec) * 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nano returns ts as the number of nanoseconds elapsed since the Unix epoch.
|
// Nano returns the time stored in ts as nanoseconds.
|
||||||
func (ts *Timespec) Nano() int64 {
|
func (ts *Timespec) Nano() int64 {
|
||||||
return int64(ts.Sec)*1e9 + int64(ts.Nsec)
|
return int64(ts.Sec)*1e9 + int64(ts.Nsec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nano returns tv as the number of nanoseconds elapsed since the Unix epoch.
|
// Nano returns the time stored in tv as nanoseconds.
|
||||||
func (tv *Timeval) Nano() int64 {
|
func (tv *Timeval) Nano() int64 {
|
||||||
return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
|
return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,10 @@
|
||||||
|
|
||||||
package syscall
|
package syscall
|
||||||
|
|
||||||
// TimespecToNsec converts a Timespec value into a number of
|
// TimespecToNSec returns the time stored in ts as nanoseconds.
|
||||||
// nanoseconds since the Unix epoch.
|
|
||||||
func TimespecToNsec(ts Timespec) int64 { return ts.Nano() }
|
func TimespecToNsec(ts Timespec) int64 { return ts.Nano() }
|
||||||
|
|
||||||
// NsecToTimespec takes a number of nanoseconds since the Unix epoch
|
// NsecToTimespec converts a number of nanoseconds into a Timespec.
|
||||||
// and returns the corresponding Timespec value.
|
|
||||||
func NsecToTimespec(nsec int64) Timespec {
|
func NsecToTimespec(nsec int64) Timespec {
|
||||||
sec := nsec / 1e9
|
sec := nsec / 1e9
|
||||||
nsec = nsec % 1e9
|
nsec = nsec % 1e9
|
||||||
|
|
@ -22,12 +20,10 @@ func NsecToTimespec(nsec int64) Timespec {
|
||||||
return setTimespec(sec, nsec)
|
return setTimespec(sec, nsec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimevalToNsec converts a Timeval value into a number of nanoseconds
|
// TimevalToNsec returns the time stored in tv as nanoseconds.
|
||||||
// since the Unix epoch.
|
|
||||||
func TimevalToNsec(tv Timeval) int64 { return tv.Nano() }
|
func TimevalToNsec(tv Timeval) int64 { return tv.Nano() }
|
||||||
|
|
||||||
// NsecToTimeval takes a number of nanoseconds since the Unix epoch
|
// NsecToTimeval converts a number of nanoseconds into a Timeval.
|
||||||
// and returns the corresponding Timeval value.
|
|
||||||
func NsecToTimeval(nsec int64) Timeval {
|
func NsecToTimeval(nsec int64) Timeval {
|
||||||
nsec += 999 // round up to microsecond
|
nsec += 999 // round up to microsecond
|
||||||
usec := nsec % 1e9 / 1e3
|
usec := nsec % 1e9 / 1e3
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue