aboutsummaryrefslogtreecommitdiff
path: root/cpu.c
diff options
context:
space:
mode:
authorInqiyad Sabr <sabr@ariamath.xyz>2025-10-20 11:55:26 +0600
committerInqiyad Sabr <sabr@ariamath.xyz>2025-10-20 11:55:26 +0600
commit658b660be1c6bd0eb2b75d51de36422a2a306dc8 (patch)
tree2643d593fd2c502e1b62332b1694b43bb605a333 /cpu.c
parentea5380fccb9f962203726540d69cb490048de7c0 (diff)
Changed every global variable to explicit variables
Diffstat (limited to 'cpu.c')
-rw-r--r--cpu.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/cpu.c b/cpu.c
index 0d53461..9573f96 100644
--- a/cpu.c
+++ b/cpu.c
@@ -2,37 +2,37 @@
#include "block.h"
#define ICON_CPU " "
FILE *proc_stat;
-int stat[8], cpu_delay = 6;
-double prev_idle, prev_total, total, idle, usage_p;
-char usage_str[11];
+int cpu_stat[8], cpu_delay = 6;
+char cpu_str[11];
void cpu(void) {
if (cpu_delay++ < 6) goto show_stat;
else cpu_delay = 0;
+ double prev_idle, prev_total, total, idle, usage_p;
prev_idle = idle;
prev_total = total;
if (!proc_stat) proc_stat = fopen("/proc/stat","r");
if (proc_stat) {
int c, i;
fseek(proc_stat,5,0);
- for (i = 0;i < 8;i++) stat[i] = 0;
+ for (i = 0;i < 8;i++) cpu_stat[i] = 0;
for (i = 0; i < 8;) {
c = fgetc(proc_stat);
if (c != ' ')
- stat[i] = 10 * stat[i] + (c - '0');
+ cpu_stat[i] = 10 * cpu_stat[i] + (c - '0');
else i++;
}
- total = stat[0]+stat[1]+stat[2];
- idle = stat[3]+stat[4];
- total += stat[5]+stat[6]+stat[7];
+ total = cpu_stat[0]+cpu_stat[1]+cpu_stat[2];
+ idle = cpu_stat[3]+cpu_stat[4];
+ total += cpu_stat[5]+cpu_stat[6]+cpu_stat[7];
}
usage_p = (idle + total) - (prev_idle + prev_total);
usage_p -= (idle - prev_idle);
usage_p *= 100;
usage_p /= (idle + total) - (prev_idle + prev_total);
- snprintf(usage_str,11,ICON_CPU"%02.2f%%",usage_p);
+ snprintf(cpu_str,11,ICON_CPU"%02.2f%%",usage_p);
show_stat:
if (usage_p < 60)
- block(usage_str,"#222222","#acae3299","#acae3299");
+ block(cpu_str,"#222222","#acae3299","#acae3299");
else
- block(usage_str,"#222222","#ea544399","#ea544399");
+ block(cpu_str,"#222222","#ea544399","#ea544399");
}