X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/acfa1f50c24add6b9a78d94af21f9350150fb9c2..d518472e6235dde0164115cd68f383f3db3427f2:/components/temperature.c diff --git a/components/temperature.c b/components/temperature.c index 45fbc9b..8462d0f 100644 --- a/components/temperature.c +++ b/components/temperature.c @@ -3,6 +3,7 @@ #include "../util.h" + #if defined(__linux__) #include @@ -11,7 +12,7 @@ { uintmax_t temp; - if(pscanf(file, "%ju", &temp) != 1) { + if (pscanf(file, "%ju", &temp) != 1) { return NULL; } @@ -46,4 +47,25 @@ /* kelvin to celsius */ return bprintf("%d", (temp.value - 273150000) / 1E6); } +#elif defined(__FreeBSD__) + #include + #include + #include + + const char * + temp(const char *zone) + { + char buf[256]; + int temp; + size_t len; + + len = sizeof(temp); + snprintf(buf, sizeof(buf), "hw.acpi.thermal.%s.temperature", zone); + if (sysctlbyname(buf, &temp, &len, NULL, 0) == -1 + || !len) + return NULL; + + /* kelvin to decimal celcius */ + return bprintf("%d.%d", (temp - 2731) / 10, abs((temp - 2731) % 10)); + } #endif