Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
5 #include <sys/sysctl.h>
8 #include "../../util.h"
20 struct timeval boottime
;
25 mib
[1] = KERN_BOOTTIME
;
27 size
= sizeof(boottime
);
29 if (sysctl(mib
, 2, &boottime
, &size
, NULL
, 0) != -1)
30 uptime
= now
- boottime
.tv_sec
;
32 fprintf(stderr
, "sysctl 'KERN_BOOTTIME': %s\n", strerror(errno
));
37 m
= (uptime
- h
* 3600) / 60;
39 return bprintf("%dh %dm", h
, m
);