not ignoring the result of fscanf

This commit is contained in:
Linus Dierheimer
2021-02-18 23:04:31 +01:00
parent 4b2c4a8821
commit 41120ef582
2 changed files with 12 additions and 4 deletions
+10 -3
View File
@@ -2,26 +2,33 @@
void ffPrintBattery(FFstate* state)
{
int scanned;
FILE* fullFile = fopen("/sys/class/power_supply/BAT0/charge_full", "r");
if(fullFile == NULL)
return;
uint32_t full;
fscanf(fullFile, "%lu", &full);
scanned = fscanf(fullFile, "%lu", &full);
if(scanned != 1)
return;
fclose(fullFile);
FILE* nowFile = fopen("/sys/class/power_supply/BAT0/charge_full", "r");
if(nowFile == NULL)
return;
uint32_t now;
fscanf(nowFile, "%lu", &now);
scanned = fscanf(nowFile, "%lu", &now);
if(scanned != 1)
return;
fclose(nowFile);
FILE* statusFile = fopen("/sys/class/power_supply/BAT0/status", "r");
if(statusFile == NULL)
return;
char status[256];
fscanf(statusFile, "%s", status);
scanned = fscanf(statusFile, "%s", status);
if(scanned != 1)
return;
fclose(statusFile);
uint32_t percentage = (now / (double) full) * 100;
+2 -1
View File
@@ -17,7 +17,8 @@ void printTerminalName(const char* pid)
char name[256];
char ppid[256];
fscanf(stat, "%*s (%[^)])%*s%s", name, ppid);
if(fscanf(stat, "%*s (%[^)])%*s%s", name, ppid) != 2)
return;
fclose(stat);