8db1c4550d8ea1455200ab1f15b3bc4acf1de420
[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
7 void status_uptime()
8 {
9         char stline[16];
10         int stfile;
11         size_t stlen;
12         int i;
13         int upts, uptm, upth, uptd;
14         
15         stfile = open("/proc/uptime", 0);
16         if (stfile != -1)
17         {
18                 stlen = read(stfile, stline, sizeof(stline));
19                 close(stfile);
20                 
21                 for(i = 0; i < stlen; i++)
22                         if (stline[i] == ' ')
23                                 stline[i] = '\0';
24                 
25                 upts = atoi(stline);
26                 uptd = upts / (24 * 60 * 60);
27                 upts -= uptd * (24 * 60 * 60);
28                 upth = upts / (60 * 60);
29                 upts -= upth * (60 * 60);
30                 uptm = upts / (60);
31                 upts -= uptm * (60);
32                 
33                 fputs(" ^fg(#AAAAAA)up: ", stdout);
34                 
35                 if (uptd > 0)
36                         printf("%dd ", uptd);
37                 
38                 printf("%d:%.2d"
39                         
40                         #ifdef SHOW_SECONDS
41                         ":%.2d"
42                         #endif
43                         
44                         " "
45                         ,upth
46                         ,uptm
47                         
48                         #ifdef SHOW_SECONDS
49                         ,upts
50                         #endif
51                         );
52         }
53 }