1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
diff -ur xfce4-battery-plugin-0.5.0.orig/panel-plugin/libacpi.c xfce4-battery-plugin-0.5.0/panel-plugin/libacpi.c
--- xfce4-battery-plugin-0.5.0.orig/panel-plugin/libacpi.c 2007-01-17 19:56:51.000000000 +0200
+++ xfce4-battery-plugin-0.5.0/panel-plugin/libacpi.c 2007-02-09 16:34:40.000000000 +0200
@@ -30,6 +30,7 @@
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
+#include <glob.h>
#if HAVE_SYSCTL
@@ -181,6 +182,22 @@
#endif
#endif
+/* expand file name and fopen first match */
+static FILE *
+fopen_glob(const char *name, const char *mode)
+{
+ glob_t globbuf;
+ FILE *fd;
+
+ if (glob(name, 0, NULL, &globbuf) != 0)
+ return NULL;
+
+ fd = fopen(globbuf.gl_pathv[0], mode);
+ globfree(&globbuf);
+
+ return fd;
+}
+
/* see if we have ACPI support */
int check_acpi(void)
{
@@ -693,7 +710,7 @@
else return 0;
}
proc_fan_status="/proc/acpi/fan/*/state";
- if ( (fp=fopen(proc_fan_status, "r")) == NULL ) return 0;
+ if ( (fp=fopen_glob(proc_fan_status, "r")) == NULL ) return 0;
fgets(line,255,fp);
fclose(fp);
@@ -706,10 +723,10 @@
{
#ifdef __linux__
FILE *fp;
- char *proc_temperature="/proc/acpi/thermal_zone/*0/temperature";
+ char *proc_temperature="/proc/acpi/thermal_zone/*/temperature";
static char *p,line[256];
- if ( (fp=fopen(proc_temperature, "r")) == NULL) return NULL;
+ if ( (fp=fopen_glob(proc_temperature, "r")) == NULL) return NULL;
fgets(line,255,fp);
fclose(fp);
p=strtok(line," ");
|