--- xfce4-battery-plugin-0.3.0/panel-plugin/libacpi.c.orig 2003-09-09 15:49:16.000000000 +0200 +++ xfce4-battery-plugin-0.3.0/panel-plugin/libacpi.c 2005-11-22 19:53:06.000000000 +0100 @@ -40,6 +40,7 @@ #include #include #include +#include #if HAVE_SYSCTL #include @@ -179,6 +180,22 @@ #endif +/* expand file name and fopen first match for reading */ +static FILE * +fopen_glob(char *name) +{ + glob_t globbuf; + FILE *fd; + + if (glob(name, 0, NULL, &globbuf) != 0) + return NULL; + + fd = fopen(globbuf.gl_pathv[0], "r"); + globfree(&globbuf); + + return fd; +} + /* see if we have ACPI support */ int check_acpi(void) { @@ -273,11 +290,8 @@ char *ptr; char stat; - if (!(acpi = fopen ("/proc/acpi/ac_adapter/0/status", "r"))) - if (!(acpi = fopen ("/proc/acpi/ac_adapter/ACAD/state", "r"))) - if (!(acpi = fopen ("/proc/acpi/ac_adapter/AC/state", "r"))) - if (!(acpi = fopen ("/proc/acpi/ac_adapter/ADP1/state", "r"))) - return -1; + if ((acpi = fopen_glob("/proc/acpi/ac_adapter/*/stat*")) == NULL) + return -1; fread (buf, 512, 1, acpi); fclose (acpi); @@ -671,9 +685,9 @@ if (strlen(line) && strstr(line,"1")) return 1; else return 0; } - proc_fan_status="/proc/acpi/fan/FAN/state"; - if ( (fp=fopen(proc_fan_status, "r")) == NULL ) return 0; - + if ((fp = fopen_glob("/proc/acpi/fan/*/stat*")) == NULL) + return 0; + fgets(line,255,fp); fclose(fp); @@ -685,10 +699,11 @@ { #ifdef __linux__ FILE *fp; - char *proc_temperature="/proc/acpi/thermal_zone/THRM/temperature"; static char *p,line[256]; - if ( (fp=fopen(proc_temperature, "r")) == NULL) return NULL; + if ((fp = fopen_glob("/proc/acpi/thermal_zone/*/temperature")) == NULL) + return NULL; + fgets(line,255,fp); fclose(fp); p=strtok(line," ");