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 *path, const char *format) {
30 asprintf(&thermal_zone, THERMAL_ZONE, zone);
34 for (walk = format; *walk != '\0'; walk++) {
40 if (BEGINS_WITH(walk+1, "degrees")) {
43 if (!slurp(path, buf, sizeof(buf)))
45 temp = strtol(buf, NULL, 10);
46 if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
49 (void)printf("%ld", (temp/1000));
50 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
52 size_t sysctl_size = sizeof(sysctl_rslt);
53 if (sysctlbyname(path, &sysctl_rslt, &sysctl_size, NULL, 0))
56 (void)printf("%d.%d", TZ_KELVTOC(sysctl_rslt));
58 walk += strlen("degrees");
64 (void)fputs("Cannot read temperature\n", stderr);