My slstatus configuration
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.
 
 
 
 

50 lines
872 B

  1. /* See LICENSE file for copyright and license details. */
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #if defined(__linux__)
  6. #include <sys/sysinfo.h>
  7. #elif defined(__OpenBSD__)
  8. #include <sys/sysctl.h>
  9. #include <sys/time.h>
  10. #endif
  11. #include "../util.h"
  12. const char *
  13. uptime(void)
  14. {
  15. int h;
  16. int m;
  17. int uptime = 0;
  18. #if defined(__linux__)
  19. struct sysinfo info;
  20. sysinfo(&info);
  21. uptime = info.uptime;
  22. #elif defined(__OpenBSD__)
  23. int mib[2];
  24. size_t size;
  25. time_t now;
  26. struct timeval boottime;
  27. time(&now);
  28. mib[0] = CTL_KERN;
  29. mib[1] = KERN_BOOTTIME;
  30. size = sizeof(boottime);
  31. if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1)
  32. uptime = now - boottime.tv_sec;
  33. else {
  34. fprintf(stderr, "sysctl 'KERN_BOOTTIME': %s\n", strerror(errno));
  35. return NULL;
  36. }
  37. #endif
  38. h = uptime / 3600;
  39. m = (uptime - h * 3600) / 60;
  40. return bprintf("%dh %dm", h, m);
  41. }