Xinqi Bao's Git

Build Linux-only functions only on Linux
[slstatus.git] / components / uptime.c
1 /* See LICENSE file for copyright and license details. */
2 #ifdef __linux__
3 #include <sys/sysinfo.h>
4
5 #include "../util.h"
6
7 const char *
8 uptime(void)
9 {
10 struct sysinfo info;
11 int h = 0;
12 int m = 0;
13
14 sysinfo(&info);
15 h = info.uptime / 3600;
16 m = (info.uptime - h * 3600 ) / 60;
17
18 return bprintf("%dh %dm", h, m);
19 }
20 #endif