9 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
11 #include <sys/types.h>
12 #include <sys/sysctl.h>
14 #define TZ_KELVTOC(x) (((x) - TZ_ZEROC) / 10), abs(((x) - TZ_ZEROC) % 10)
17 static char *thermal_zone;
20 * Reads the CPU temperature from /sys/class/thermal/thermal_zone0/temp and
21 * returns the temperature in degree celcius.
24 void print_cpu_temperature_info(int zone, const char *format) {
28 asprintf(&thermal_zone, THERMAL_ZONE, zone);
30 for (walk = format; *walk != '\0'; walk++) {
36 if (BEGINS_WITH(walk+1, "degrees")) {
39 if (!slurp(thermal_zone, buf, sizeof(buf)))
40 die("Could not open \"%s\"\n", thermal_zone);
41 temp = strtol(buf, NULL, 10);
42 if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
45 (void)printf("%ld", (temp/1000));
46 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
48 size_t sysctl_size = sizeof(sysctl_rslt);
49 if (sysctlbyname(thermal_zone, &sysctl_rslt, &sysctl_size, NULL, 0)) {
50 (void)printf("No thermal zone found");
54 (void)printf("%d.%d", TZ_KELVTOC(sysctl_rslt));
56 walk += strlen("degrees");