My slstatus configuration
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

46 righe
760 B

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