More cleanup, 'temp' and 'uptime' use fileRead().
[sysstatus.git] / statuses / temp.c
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <unistd.h>
4 #include "temp.h"
5
6 void status_temp(char *title, char *sysfile)
7 {
8         char stline[16];
9         int stfile;
10         ssize_t stlen;
11
12         stlen = fileRead(stline, sizeof(stline), sysfile);
13         if (stlen <= 0)
14                 return;
15
16         // Read a valid value? Sometimes we get garbage from sysfs...
17         if (stlen < 6 || stlen > 7)
18         {
19                 printf(" ^fg(red)%sERROR ", title);
20                 return;
21         }
22
23         fputs(" ^fg(#FF33FF)", stdout);
24         fputs(title, stdout);
25         fwrite(stline, 1, stlen - 4, stdout);
26         /*
27         fputs(".", stdout);
28         fwrite(&stline[stlen - 3], 1, 1, stdout);
29         */
30         fputs("°C ", stdout);
31 }