Xinqi Bao's Git

Makefile: add distclean target
[slstatus.git] / components / OpenBSD / temperature.c
1 /* See LICENSE file for copyright and license details. */
2 #include <errno.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <sys/sysctl.h>
6 #include <sys/time.h>
7 #include <sys/sensors.h>
8
9 #include "../../util.h"
10
11 const char *
12 temp(const char *null)
13 {
14 int mib[5];
15 size_t size;
16 struct sensor temp;
17
18 mib[0] = CTL_HW;
19 mib[1] = HW_SENSORS;
20 mib[2] = 0; /* cpu0 */
21 mib[3] = SENSOR_TEMP;
22 mib[4] = 0; /* temp0 */
23
24 size = sizeof(temp);
25
26 if (sysctl(mib, 5, &temp, &size, NULL, 0) == -1) {
27 fprintf(stderr, "sysctl 'SENSOR_TEMP': %s\n", strerror(errno));
28 return NULL;
29 }
30
31 return bprintf("%d", (temp.value - 273150000) / 1000000); /* kelvin to celsius */
32 }