X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/d1e33988227bf88c6bc33d4f83274dda78ee2310..86849d295b1eb9e18746d8a4fa196fe7b9dce0dc:/components/temperature.c diff --git a/components/temperature.c b/components/temperature.c index 2c57853..8462d0f 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) { - uint64_t temp; + uintmax_t temp; - if(pscanf(file, "%" PRIu64, &temp) != 1) { + if (pscanf(file, "%ju", &temp) != 1) { return NULL; } - return bprintf("%" PRIu64, temp / 1000); + return bprintf("%ju", temp / 1000); } #elif defined(__OpenBSD__) #include @@ -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