Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
11 temp(const char *file
)
15 if (pscanf(file
, "%ju", &temp
) != 1) {
19 return bprintf("%ju", temp
/ 1000);
21 #elif defined(__OpenBSD__)
23 #include <sys/time.h> /* before <sys/sensors.h> for struct timeval */
24 #include <sys/sensors.h>
25 #include <sys/sysctl.h>
28 temp(const char *unused
)
36 mib
[2] = 0; /* cpu0 */
38 mib
[4] = 0; /* temp0 */
42 if (sysctl(mib
, 5, &temp
, &size
, NULL
, 0) < 0) {
43 warn("sysctl 'SENSOR_TEMP':");
47 /* kelvin to celsius */
48 return bprintf("%d", (temp
.value
- 273150000) / 1E6
);
50 #elif defined(__FreeBSD__)
53 #include <sys/sysctl.h>
56 temp(const char *zone
)
63 snprintf(buf
, sizeof(buf
), "hw.acpi.thermal.%s.temperature", zone
);
64 if (sysctlbyname(buf
, &temp
, &len
, NULL
, 0) == -1
68 /* kelvin to decimal celcius */
69 return bprintf("%d.%d", (temp
- 2731) / 10, abs((temp
- 2731) % 10));