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) {
29 asprintf(&thermal_zone, THERMAL_ZONE, zone);
33 for (walk = format; *walk != '\0'; walk++) {
39 if (BEGINS_WITH(walk+1, "degrees")) {
42 if (!slurp(path, buf, sizeof(buf)))
43 die("Could not open \"%s\"\n", path);
44 temp = strtol(buf, NULL, 10);
45 if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
48 (void)printf("%ld", (temp/1000));
49 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
51 size_t sysctl_size = sizeof(sysctl_rslt);
52 if (sysctlbyname(path, &sysctl_rslt, &sysctl_size, NULL, 0)) {
53 (void)printf("No thermal zone found");
57 (void)printf("%d.%d", TZ_KELVTOC(sysctl_rslt));
59 walk += strlen("degrees");