Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
10 temp(const char *file
)
14 if(pscanf(file
, "%" PRIu64
, &temp
) != 1) {
18 return bprintf("%" PRIu64
, temp
/ 1000);
20 #elif defined(__OpenBSD__)
22 #include <sys/time.h> /* before <sys/sensors.h> for struct timeval */
23 #include <sys/sensors.h>
24 #include <sys/sysctl.h>
27 temp(const char *unused
)
35 mib
[2] = 0; /* cpu0 */
37 mib
[4] = 0; /* temp0 */
41 if (sysctl(mib
, 5, &temp
, &size
, NULL
, 0) < 0) {
42 warn("sysctl 'SENSOR_TEMP':");
46 /* kelvin to celsius */
47 return bprintf("%d", (temp
.value
- 273150000) / 1E6
);