X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/43a12832a343747b7317987b552a87eb8ed5b42d..3da6b8bb87ff3fe22329edf0d09ab43f5163eb3c:/components/temperature.c?ds=inline diff --git a/components/temperature.c b/components/temperature.c index 71e1378..8e1f222 100644 --- a/components/temperature.c +++ b/components/temperature.c @@ -3,19 +3,20 @@ #include "../util.h" + #if defined(__linux__) - #include + #include const char * temp(const char *file) { uintmax_t temp; - if(pscanf(file, "%" PRIuMAX, &temp) != 1) { + if (pscanf(file, "%ju", &temp) != 1) { return NULL; } - return bprintf("%" PRIuMAX, temp / 1000); + return bprintf("%ju", temp / 1000); } #elif defined(__OpenBSD__) #include @@ -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