1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris
9 // TimespecToNsec converts a Timespec value into a number of
10 // nanoseconds since the Unix epoch.
11 func TimespecToNsec(ts Timespec
) int64 { return int64(ts
.Sec
)*1e9
+ int64(ts
.Nsec
) }
13 // NsecToTimespec takes a number of nanoseconds since the Unix epoch
14 // and returns the corresponding Timespec value.
15 func NsecToTimespec(nsec
int64) Timespec
{
22 return setTimespec(sec
, nsec
)
25 // TimevalToNsec converts a Timeval value into a number of nanoseconds
26 // since the Unix epoch.
27 func TimevalToNsec(tv Timeval
) int64 { return int64(tv
.Sec
)*1e9
+ int64(tv
.Usec
)*1e3
}
29 // NsecToTimeval takes a number of nanoseconds since the Unix epoch
30 // and returns the corresponding Timeval value.
31 func NsecToTimeval(nsec
int64) Timeval
{
32 nsec
+= 999 // round up to microsecond
33 usec
:= nsec
% 1e9
/ 1e3
39 return setTimeval(sec
, usec
)