代码拉取完成,页面将自动刷新
同步操作将从 src-oepkgs/acpitool 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
Author: Michael Meskes <meskes@debian.org>
Description: Fix reading of ac_adapter information.
--- acpitool-0.5.1/src/ac_adapter.cpp 2009-08-13 21:26:02.000000000 +0200
+++ acpitool-0.5.1.fixed/src/ac_adapter.cpp 2010-03-09 12:26:22.000000000 +0100
@@ -149,7 +149,7 @@
int Do_AC_Info_Sys()
{
ifstream file_in;
- char filename[2][65], str[100], temp[100];
+ char filename[2][65], str[100], temp[100], attr[100];
int ac_count = 0, start = 0, findex = 0;
DIR *ac_dir;
char *name, *dirname;
@@ -206,31 +206,40 @@
if(ac_count>0)
{
- for(int i=0; i<ac_count; i++) /* I don't expect to find > 1, but you never know */
+ for(int i=0, t=0; i<ac_count; i++) /* I don't expect to find > 1, but you never know */
{
FILE *power_fp = fopen(filename[i], "r");
if(power_fp)
{
- for(int t=0; t<5; t++)
- fgets(str, 100, power_fp); /* just skip the first 5 lines */
-
- memset(str, '\0', 100);
- fgets(str, 100, power_fp);
+ // see linux-2.6/drivers/power/power_supply_sysfs.c
+ // there can be different number of lines, so read up to 40 lines
+ for(; t<40; t++)
+ {
+ memset(str, '\0', 100);
+ fgets(str, 100, power_fp);
- if (strlen(str)!=0)
- {
- memset(temp, '\0', 100);
- sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
+ if (strlen(str)!=0)
+ {
+ memset(temp, '\0', 100);
+ memset(attr, '\0', 100);
+ sscanf(str, "%[^=]s %*s %[^\n]", attr);
+ sscanf(str, "%*[^=] %*c %s %[^\n]",temp);
- /* keep this for debugging */
- /* printf(" from Do_AC_SYS: temp = %s \n", temp);*/
-
- if(strncmp(temp,"1",1)==0)
- printf(" AC adapter : online \n");
- else
- printf(" AC adapter : off-line \n");
+ /* keep this for debugging */
+ /* printf(" from Do_AC_SYS: temp = %s \n", temp);*/
+
+ if (strcmp(attr, "POWER_SUPPLY_ONLINE") == 0)
+ {
+ if(strncmp(temp,"1",1)==0)
+ printf(" AC adapter : online \n");
+ else
+ printf(" AC adapter : off-line \n");
+
+ break;
+ }
+ }
}
- else
+ if (t == 40)
printf(" AC adapter : <info not available> \n");
}
else
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。