Xinqi Bao's Git

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