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