Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
12 m
= (uptime
- h
* 3600) / 60;
14 return bprintf("%dh %dm", h
, m
);
17 #if defined(__linux__)
18 #include <sys/sysinfo.h>
29 return format(uptime
);
31 #elif defined(__OpenBSD__)
34 #include <sys/sysctl.h>
43 struct timeval boottime
;
48 mib
[1] = KERN_BOOTTIME
;
50 size
= sizeof(boottime
);
52 if (sysctl(mib
, 2, &boottime
, &size
, NULL
, 0) < 0) {
53 fprintf(stderr
, "sysctl 'KERN_BOOTTIME': %s\n", strerror(errno
));
57 uptime
= now
- boottime
.tv_sec
;
59 return format(uptime
);