uptime.c 388 B

12345678910111213141516171819
  1. /* See LICENSE file for copyright and license details. */
  2. #include <time.h>
  3. #include <stdio.h>
  4. #include "../util.h"
  5. const char *
  6. uptime(void)
  7. {
  8. int h, m;
  9. struct timespec uptime;
  10. if (clock_gettime(CLOCK_BOOTTIME, &uptime) < 0) {
  11. warn("clock_gettime 'CLOCK_BOOTTIME'");
  12. return NULL;
  13. }
  14. h = uptime.tv_sec / 3600;
  15. m = uptime.tv_sec % 3600 / 60;
  16. return bprintf("%dh %dm", h, m);
  17. }