My slstatus configuration
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

34 行
650 B

  1. /* See LICENSE file for copyright and license details. */
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include <time.h>
  5. #include "../util.h"
  6. #if defined(CLOCK_BOOTTIME)
  7. #define UPTIME_FLAG CLOCK_BOOTTIME
  8. #elif defined(CLOCK_UPTIME)
  9. #define UPTIME_FLAG CLOCK_UPTIME
  10. #else
  11. #define UPTIME_FLAG CLOCK_MONOTONIC
  12. #endif
  13. const char *
  14. uptime(void)
  15. {
  16. char warn_buf[256];
  17. uintmax_t h, m;
  18. struct timespec uptime;
  19. if (clock_gettime(UPTIME_FLAG, &uptime) < 0) {
  20. snprintf(warn_buf, 256, "clock_gettime %d", UPTIME_FLAG);
  21. warn(warn_buf);
  22. return NULL;
  23. }
  24. h = uptime.tv_sec / 3600;
  25. m = uptime.tv_sec % 3600 / 60;
  26. return bprintf("%juh %jum", h, m);
  27. }