diff --git a/internal/timespec/timespec.go b/internal/timespec/timespec.go index 54076e3..1e4b09a 100644 --- a/internal/timespec/timespec.go +++ b/internal/timespec/timespec.go @@ -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) +}