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 if (output_format == O_I3BAR)
35 printf("{\"name\":\"cpu_temperature\", \"instance\": \"%s\", \"full_text\":\"", path);
37 for (walk = format; *walk != '\0'; walk++) {
43 if (BEGINS_WITH(walk+1, "degrees")) {
46 if (!slurp(path, buf, sizeof(buf)))
48 temp = strtol(buf, NULL, 10);
49 if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
52 (void)printf("%ld", (temp/1000));
53 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
55 size_t sysctl_size = sizeof(sysctl_rslt);
56 if (sysctlbyname(path, &sysctl_rslt, &sysctl_size, NULL, 0))
59 (void)printf("%d.%d", TZ_KELVTOC(sysctl_rslt));
61 walk += strlen("degrees");
65 if (output_format == O_I3BAR)
71 (void)fputs("Cannot read temperature\n", stderr);