]> git.sur5r.net Git - i3/i3status/blob - src/get_cpu_temperature.c
Add modelines and retab! all files
[i3/i3status] / src / get_cpu_temperature.c
1 // vim:ts=8:expandtab
2 #include <stdlib.h>
3 #include <limits.h>
4 #include <stdio.h>
5
6 #include "i3status.h"
7
8 /*
9  * Reads the CPU temperature from /sys/class/thermal/thermal_zone0/temp and
10  * returns the temperature in degree celcius.
11  *
12  */
13 const char *get_cpu_temperature_info() {
14         static char buf[16];
15         long int temp;
16
17         slurp(thermal_zone, buf, sizeof(buf));
18         temp = strtol(buf, NULL, 10);
19
20         if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
21                 (void)snprintf(buf, sizeof(buf), "T: ? C");
22         else
23                 (void)snprintf(buf, sizeof(buf), "T: %ld C", (temp/1000));
24
25         return buf;
26 }