+ char *buf_itr = NULL;
+ for (int idx = 0; idx < curr_cpu_count; ++idx) {
+ buf_itr = strtok(NULL, "\n");
+ int cpu_idx, user, nice, system, idle;
+ if (!buf_itr || sscanf(buf_itr, "cpu%d %d %d %d %d", &cpu_idx, &user, &nice, &system, &idle) != 5) {
+ goto error;
+ }
+ if (cpu_idx < 0 || cpu_idx >= cpu_count)
+ goto error;
+ curr_cpus[cpu_idx].user = user;
+ curr_cpus[cpu_idx].nice = nice;
+ curr_cpus[cpu_idx].system = system;
+ curr_cpus[cpu_idx].idle = idle;
+ curr_cpus[cpu_idx].total = user + nice + system + idle;
+ }
+ for (int cpu_idx = 0; cpu_idx < cpu_count; cpu_idx++) {
+ 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;
+ }