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