+ // Parsing all cpu values using strtok
+ if (strtok(buf, "\n") == NULL)
+ goto error;
+ char *buf_itr = NULL;
+ for (int cpu_idx = 0; cpu_idx < cpu_count; cpu_idx++) {
+ buf_itr = strtok(NULL, "\n");
+ int curr_cpu_idx = -1;
+ if (!buf_itr || sscanf(buf_itr, "cpu%d %d %d %d %d", &curr_cpu_idx, &curr_cpus[cpu_idx].user, &curr_cpus[cpu_idx].nice, &curr_cpus[cpu_idx].system, &curr_cpus[cpu_idx].idle) != 5 || curr_cpu_idx != cpu_idx)
+ goto error;
+ curr_cpus[cpu_idx].total = curr_cpus[cpu_idx].user + curr_cpus[cpu_idx].nice + curr_cpus[cpu_idx].system + curr_cpus[cpu_idx].idle;
+ curr_all.user += curr_cpus[cpu_idx].user;
+ curr_all.nice += curr_cpus[cpu_idx].nice;
+ curr_all.system += curr_cpus[cpu_idx].system;
+ curr_all.idle += curr_cpus[cpu_idx].idle;
+ curr_all.total += curr_cpus[cpu_idx].total;
+ }