erm/internal/app/darktile/hinters/uptime.go
Qiu 97b6a41eb3
Make getting the up-time more portable across unix-like systems (#326)
* Make getting the up-time more portable across unix-like systems

* Fix the build on NetBSD

* Update Go version in workflows
2021-12-17 08:39:48 +00:00

24 lines
328 B
Go

//go:build cgo && (freebsd || openbsd)
package hinters
/*
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/timespec.h>
time_t getuptime() {
struct timespec tp;
clock_gettime(CLOCK_UPTIME, &tp);
return tp.tv_sec;
}
*/
import "C"
func getUptime() int64 {
time := C.getuptime()
return int64(time)
}