blob: a6dac938d3e63a942007e5f3837e8d66c7c1778d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "cpu.h"
#include "../utils/utils.h"
int cpu(void) {
FILE* file = fopen("/proc/cpuinfo", "r");
//check file existence
if (!file) {
perror("/proc/cpuinfo not found");
return 1;
}
char line[256];
char *model_name = NULL;
//read per line
while (fgets(line, sizeof(line), file)) {
char* p = strstr(line, "model name");
if (p != NULL) {
model_name = strchr(p, ':') + 1; //skip :
break;
}
}
if (model_name != NULL) {
char *string = string_format(model_name);
if (string == NULL) {
printf("CPU: Error string not found.\n");
free(string);
model_name = NULL;
} else {
printf("CPU: %s\n", string);
free(string);
model_name = NULL;
}
} else {
printf("CPU: Error model_name not found.\n");
}
fclose(file);
return 0;
}
|