1 Star 0 Fork 1

steve/acpitool

forked from src-oepkgs/acpitool 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ac_adapter.patch 2.31 KB
一键复制 编辑 原始数据 按行查看 历史
张一诺 提交于 2022-11-21 16:39 . 0.5.1
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/stlesson/acpitool.git
git@gitee.com:stlesson/acpitool.git
stlesson
acpitool
acpitool
master

搜索帮助