timespec: add a helper function to convert from Timespec to C

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2020-06-25 15:37:25 -04:00 committed by mergify[bot]
parent 6900146fc4
commit 29ebb61850
1 changed files with 9 additions and 0 deletions

View File

@ -28,3 +28,12 @@ func CStructToTimespec(cts CTimespecPtr) Timespec {
Nsec: int64(t.tv_nsec),
}
}
// CopyToCStruct copies the time values from a Timespec to a previously
// allocated C `struct timespec`. Due to restrictions on Cgo the C pointer
// must be passed via the CTimespecPtr wrapper.
func CopyToCStruct(ts Timespec, cts CTimespecPtr) {
t := (*C.struct_timespec)(cts)
t.tv_sec = C.time_t(ts.Sec)
t.tv_nsec = C.long(ts.Nsec)
}