Reindent and restyle
[sysstatus.git] / statuses / uptime.c
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <unistd.h>
4 #include <stdlib.h>
5 #include "uptime.h"
6 #include "../config.h"
7
8 void status_uptime()
9 {
10   char stline[16];
11   int stfile;
12   ssize_t stlen;
13   int i;
14   int upts, uptm, upth, uptd;
15
16   fputs(" ^fg(#AAAAAA)up: ", stdout);
17
18   stlen = fileRead(stline, sizeof(stline), "/proc/uptime");
19   if (stlen < 0) {
20     fputs(" ^fg(red)ERROR ", stdout);
21     return;
22   }
23
24   /* Cut first element */
25   for(i = 0; i < stlen; i++) {
26     if (stline[i] == ' ') {
27       stline[i] = '\0';
28       break;
29     }
30   }
31
32   // Split time into days, hours, mins, secs
33   upts = atoi(stline);
34   uptd = upts / (24 * 60 * 60);
35   upts -= uptd * (24 * 60 * 60);
36   upth = upts / (60 * 60);
37   upts -= upth * (60 * 60);
38   uptm = upts / (60);
39   upts -= uptm * (60);
40
41   if (uptd > 0) {
42     printf("%dd ", uptd);
43   }
44
45   printf("%d:%.2d"
46           #ifdef SHOW_SECONDS
47           ":%.2d"
48           #endif
49
50           " "
51           ,upth
52           ,uptm
53
54           #ifdef SHOW_SECONDS
55           ,upts
56           #endif
57         );
58 }