- if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1)
- uptime = now - boottime.tv_sec;
- else
- return NULL;
-#endif
- h = uptime / 3600;
- m = (uptime - h * 3600) / 60;
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_BOOTTIME;
+
+ size = sizeof(boottime);
+
+ if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1)
+ uptime = now - boottime.tv_sec;
+ else {
+ fprintf(stderr, "sysctl 'KERN_BOOTTIME': %s\n", strerror(errno));
+ return NULL;
+ }