Missing files, fix last commit.
[monky] / src / sony.c
1 /* conky support for information from sony_laptop kernel module
2  *   information from sony_laptop kernel module
3  *   /sys/devices/platform/sony-laptop
4  *   I mimicked the methods from ibm.c
5  * Yeon-Hyeong Yang <lbird94@gmail.com> */
6
7 #include "conky.h"
8 #include "config.h"
9 #include "sony.h"
10 #include "logging.h"
11 #include <stdio.h>
12 #include <errno.h>
13 #include <string.h>
14 #include <stdlib.h>
15
16 #define SONY_LAPTOP_DIR "/sys/devices/platform/sony-laptop"
17
18 /* fanspeed in SONY_LAPTOP_DIR contains an integer value for fanspeed (0~255).
19  * I don't know the exact measurement unit, though. I may assume that 0 for
20  * 'fan stopped' and 255 for 'maximum fan speed'. */
21 void get_sony_fanspeed(char *p_client_buffer, size_t client_buffer_size)
22 {
23         FILE *fp;
24         unsigned int speed = 0;
25         char fan[128];
26
27         if (!p_client_buffer || client_buffer_size <= 0) {
28                 return;
29         }
30
31         snprintf(fan, 127, "%s/fanspeed", SONY_LAPTOP_DIR);
32
33         fp = fopen(fan, "r");
34         if (fp != NULL) {
35                 while (!feof(fp)) {
36                         char line[256];
37
38                         if (fgets(line, 255, fp) == NULL) {
39                                 break;
40                         }
41                         if (sscanf(line, "%u", &speed)) {
42                                 break;
43                         }
44                 }
45         } else {
46                 CRIT_ERR("can't open '%s': %s\nEnable sony support or remove "
47                         "sony* from your "PACKAGE_NAME" config file.",
48                         fan, strerror(errno));
49         }
50
51         fclose(fp);
52         snprintf(p_client_buffer, client_buffer_size, "%d", speed);
53 }
54