My slstatus configuration
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

63 行
1009 B

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