...

Source file src/syscall/timestruct.go

Documentation: syscall

		 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.
		 4  
		 5  //go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris
		 6  // +build aix darwin dragonfly freebsd js,wasm linux netbsd openbsd solaris
		 7  
		 8  package syscall
		 9  
		10  // TimespecToNSec returns the time stored in ts as nanoseconds.
		11  func TimespecToNsec(ts Timespec) int64 { return ts.Nano() }
		12  
		13  // NsecToTimespec converts a number of nanoseconds into a Timespec.
		14  func NsecToTimespec(nsec int64) Timespec {
		15  	sec := nsec / 1e9
		16  	nsec = nsec % 1e9
		17  	if nsec < 0 {
		18  		nsec += 1e9
		19  		sec--
		20  	}
		21  	return setTimespec(sec, nsec)
		22  }
		23  
		24  // TimevalToNsec returns the time stored in tv as nanoseconds.
		25  func TimevalToNsec(tv Timeval) int64 { return tv.Nano() }
		26  
		27  // NsecToTimeval converts a number of nanoseconds into a Timeval.
		28  func NsecToTimeval(nsec int64) Timeval {
		29  	nsec += 999 // round up to microsecond
		30  	usec := nsec % 1e9 / 1e3
		31  	sec := nsec / 1e9
		32  	if usec < 0 {
		33  		usec += 1e6
		34  		sec--
		35  	}
		36  	return setTimeval(sec, usec)
		37  }
		38  

View as plain text