Xinqi Bao's Git

Mark unused parameters, fix compiler warnings
[slstatus.git] / components / temperature.c
1 /* See LICENSE file for copyright and license details. */
2 #include <stddef.h>
3
4 #include "../util.h"
5
6 #if defined(__linux__)
7 const char *
8 temp(const char *file)
9 {
10 int temp;
11
12 return (pscanf(file, "%d", &temp) == 1) ?
13 bprintf("%d", temp / 1000) : NULL;
14 }
15 #elif defined(__OpenBSD__)
16 #include <errno.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <sys/time.h> /* before <sys/sensors.h> for struct timeval */
20 #include <sys/sensors.h>
21 #include <sys/sysctl.h>
22
23 const char *
24 temp(const char *file)
25 {
26 int mib[5];
27 size_t size;
28 struct sensor temp;
29
30 UNUSED(file); /* no temperature file on OpenBSD */
31
32 mib[0] = CTL_HW;
33 mib[1] = HW_SENSORS;
34 mib[2] = 0; /* cpu0 */
35 mib[3] = SENSOR_TEMP;
36 mib[4] = 0; /* temp0 */
37
38 size = sizeof(temp);
39
40 if (sysctl(mib, 5, &temp, &size, NULL, 0) < 0) {
41 fprintf(stderr, "sysctl 'SENSOR_TEMP': %s\n",
42 strerror(errno));
43 return NULL;
44 }
45
46 /* kelvin to celsius */
47 return bprintf("%d", (temp.value - 273150000) / 1000000);
48 }
49 #endif