Xinqi Bao's Git
a3082f28f133ec6c2006fb7e600464537874440a
1 /* See LICENSE file for copyright and license details. */
6 #include <sys/sysinfo.h>
7 #elif defined(__OpenBSD__)
8 #include <sys/sysctl.h>
20 #if defined(__linux__)
25 #elif defined(__OpenBSD__)
29 struct timeval boottime
;
34 mib
[1] = KERN_BOOTTIME
;
36 size
= sizeof(boottime
);
38 if (sysctl(mib
, 2, &boottime
, &size
, NULL
, 0) != -1)
39 uptime
= now
- boottime
.tv_sec
;
41 fprintf(stderr
, "sysctl 'KERN_BOOTTIME': %s\n", strerror(errno
));
46 m
= (uptime
- h
* 3600) / 60;
48 return bprintf("%dh %dm", h
, m
);