libgo: update to Go 1.11
[official-gcc.git] / libgo / go / syscall / timestruct.go
blobd17811c1214bf4ec0fc16db5d6847dced96c0334
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 js,wasm linux nacl netbsd openbsd solaris
7 package syscall
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 {
16 sec := nsec / 1e9
17 nsec = nsec % 1e9
18 if nsec < 0 {
19 nsec += 1e9
20 sec--
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
34 sec := nsec / 1e9
35 if usec < 0 {
36 usec += 1e6
37 sec--
39 return setTimeval(sec, usec)