Xinqi Bao's Git
a5df01237a63331d20543f52fbce02aff0c07432
1 /* See LICENSE file for copyright and license details. */
5 #if defined(__OpenBSD__)
6 #include <sys/sysctl.h>
8 #include <sys/sensors.h>
13 #if defined(__linux__)
15 temp(const char *file
)
19 return (pscanf(file
, "%d", &temp
) == 1) ?
20 bprintf("%d", temp
/ 1000) : NULL
;
22 #elif defined(__OpenBSD__)
24 temp(const char *null
)
32 mib
[2] = 0; /* cpu0 */
34 mib
[4] = 0; /* temp0 */
38 if (sysctl(mib
, 5, &temp
, &sz
, NULL
, 0) == -1) {
39 fprintf(stderr
, "sysctl 'SENSOR_TEMP': %s\n", strerror(errno
));
43 return bprintf("%d", (temp
.value
- 273150000) / 1000000); /* kelvin to celsius */