@@ -74,7 +74,7 @@ void get_battery_module_name(char *buf)
7474 * module.
7575 */
7676
77- void read_sysfs_values (char * filename , void * buf , int len , int flag )
77+ int read_sysfs_values (char * filename , void * buf , int len , int flag )
7878{
7979 char sysfs_path [120 ];
8080
@@ -84,15 +84,15 @@ void read_sysfs_values(char *filename, void *buf, int len, int flag)
8484 FILE * fp = fopen (sysfs_path , "r" );
8585 if (!fp ) { /* validate file open for reading */
8686 fprintf (stderr , "Failed to open file for read.\n" );
87- return ;
87+ return - ENODEV ;
8888 }
8989
9090 if (flag == 0 )
9191 fread (buf , len , 1 , fp );
9292 else
9393 fscanf (fp , "%d" , (int * )buf ); /* read/validate value */
9494 fclose (fp );
95- return ;
95+ return 0 ;
9696}
9797
9898/* read_store_values: Read and store all the battery related sysfs values
@@ -101,19 +101,22 @@ void read_sysfs_values(char *filename, void *buf, int len, int flag)
101101
102102void read_store_values ()
103103{
104+ int ret ;
104105 read_sysfs_values (MODEL_NAME , initpkt .model_name , sizeof (initpkt .model_name ), 0 );
105106 read_sysfs_values (SERIAL_NUMBER , initpkt .serial_number , sizeof (initpkt .serial_number ), 0 );
106107 read_sysfs_values (MANUFACTURER , initpkt .manufacturer , sizeof (initpkt .manufacturer ), 0 );
107108 read_sysfs_values (TECHNOLOGY , initpkt .technology , sizeof (initpkt .technology ), 0 );
108109 read_sysfs_values (TYPE , initpkt .type , sizeof (initpkt .type ), 0 );
109110 read_sysfs_values (PRESENT , initpkt .present , sizeof (initpkt .present ), 0 );
110111 read_sysfs_values (CAPACITY , & monitorpkt .capacity , sizeof (monitorpkt .capacity ), 1 );
111- read_sysfs_values (CHARGE_FULL_DESIGN , & monitorpkt .charge_full_design , sizeof (monitorpkt .charge_full_design ), 1 );
112+ ret = read_sysfs_values (CHARGE_FULL_DESIGN , & monitorpkt .charge_full_design , sizeof (monitorpkt .charge_full_design ), 1 );
113+ if (ret != 0 ) monitorpkt .charge_full_design = 0 ;
112114 read_sysfs_values (HEALTH , monitorpkt .health , sizeof (monitorpkt .health ), 0 );
113115 read_sysfs_values (TEMP , & monitorpkt .temp , sizeof (monitorpkt .temp ), 1 );
114116 read_sysfs_values (CHARGE_NOW , & monitorpkt .charge_now , sizeof (monitorpkt .charge_now ), 1 );
115117 read_sysfs_values (TIME_TO_EMPTY_AVG , & monitorpkt .time_to_empty_avg , sizeof (monitorpkt .time_to_empty_avg ), 1 );
116- read_sysfs_values (CHARGE_FULL , & monitorpkt .charge_full , sizeof (monitorpkt .charge_full ), 1 );
118+ ret = read_sysfs_values (CHARGE_FULL , & monitorpkt .charge_full , sizeof (monitorpkt .charge_full ), 1 );
119+ if (ret != 0 ) monitorpkt .charge_full = 0 ;
117120 read_sysfs_values (TIME_TO_FULL_NOW , & monitorpkt .time_to_full_now , sizeof (monitorpkt .time_to_full_now ), 1 );
118121 read_sysfs_values (VOLTAGE_NOW , & monitorpkt .voltage_now , sizeof (monitorpkt .voltage_now ), 1 );
119122 read_sysfs_values (CHARGE_TYPE , monitorpkt .charge_type , sizeof (monitorpkt .charge_type ), 0 );
0 commit comments