mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 10:52:08 +02:00
not ignoring the result of fscanf
This commit is contained in:
+10
-3
@@ -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
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user