зеркало из https://github.com/mozilla/pjs.git
Bug 712226 - Crash when fclose(NULL)'ing a battery-status FILE*, r=mwu
This commit is contained in:
Родитель
1304408f8f
Коммит
578b5b5e49
|
@ -289,15 +289,17 @@ GetCurrentBatteryInformation(hal::BatteryInformation *aBatteryInfo)
|
|||
{
|
||||
FILE *capacityFile = fopen("/sys/class/power_supply/battery/capacity", "r");
|
||||
double capacity = dom::battery::kDefaultLevel * 100;
|
||||
if (capacityFile)
|
||||
if (capacityFile) {
|
||||
fscanf(capacityFile, "%lf", &capacity);
|
||||
fclose(capacityFile);
|
||||
fclose(capacityFile);
|
||||
}
|
||||
|
||||
FILE *chargingFile = fopen("/sys/class/power_supply/battery/charging_source", "r");
|
||||
int chargingSrc = 1;
|
||||
if (chargingFile)
|
||||
if (chargingFile) {
|
||||
fscanf(chargingFile, "%d", &chargingSrc);
|
||||
fclose(chargingFile);
|
||||
fclose(chargingFile);
|
||||
}
|
||||
|
||||
aBatteryInfo->level() = capacity / 100;
|
||||
aBatteryInfo->charging() = chargingSrc == 1;
|
||||
|
|
Загрузка…
Ссылка в новой задаче