jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
375B

  1. #include <time.h>
  2. #include <errno.h>
  3. #include <sys/sysctl.h>
  4. long uptime(void)
  5. {
  6. struct timeval boottime;
  7. size_t len = sizeof(boottime);
  8. int mib[2] = { CTL_KERN, KERN_BOOTTIME };
  9. if (sysctl(mib, 2, &boottime, &len, NULL, 0) < 0)
  10. {
  11. return -1L;
  12. }
  13. time_t bsec = boottime.tv_sec, csec = time(NULL);
  14. return (long) difftime(csec, bsec);
  15. }