8 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
10 #include <sys/types.h>
11 #include <sys/sysctl.h>
13 #define TZ_KELVTOC(x) (((x) - TZ_ZEROC) / 10), abs(((x) - TZ_ZEROC) % 10)
18 * Reads the CPU temperature from /sys/class/thermal/thermal_zone0/temp and
19 * returns the temperature in degree celcius.
22 const char *get_cpu_temperature_info() {
27 if (!slurp(thermal_zone, buf, sizeof(buf)))
28 die("Could not open \"%s\"\n", thermal_zone);
29 temp = strtol(buf, NULL, 10);
30 if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
31 (void)snprintf(buf, sizeof(buf), "T: ? C");
33 (void)snprintf(buf, sizeof(buf), "T: %ld C", (temp/1000));
34 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
36 size_t sysctl_size = sizeof (sysctl_rslt);
37 if (sysctlbyname(thermal_zone,&sysctl_rslt,&sysctl_size,NULL,0))
40 snprintf(buf,sizeof(buf),"T: %d.%d C",TZ_KELVTOC(sysctl_rslt));