My slstatus configuration
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

62 líneas
925 B

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