From 658b660be1c6bd0eb2b75d51de36422a2a306dc8 Mon Sep 17 00:00:00 2001 From: Inqiyad Sabr Date: Mon, 20 Oct 2025 11:55:26 +0600 Subject: Changed every global variable to explicit variables --- cpu.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'cpu.c') 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"); } -- cgit v1.2.3