X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/acfa1f50c24add6b9a78d94af21f9350150fb9c2..3da6b8bb87ff3fe22329edf0d09ab43f5163eb3c:/components/temperature.c?ds=sidebyside diff --git a/components/temperature.c b/components/temperature.c index 45fbc9b..8e1f222 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; } @@ -44,6 +45,27 @@ } /* kelvin to celsius */ - return bprintf("%d", (temp.value - 273150000) / 1E6); + return bprintf("%d", (int)((float)(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