aboutsummaryrefslogtreecommitdiff
path: root/src/modules/cpu
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/cpu')
-rw-r--r--src/modules/cpu/cpu.c36
-rw-r--r--src/modules/cpu/cpu.h8
2 files changed, 44 insertions, 0 deletions
diff --git a/src/modules/cpu/cpu.c b/src/modules/cpu/cpu.c
new file mode 100644
index 0000000..c2d50f3
--- /dev/null
+++ b/src/modules/cpu/cpu.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <string.h>
+#include "cpu.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) {
+ printf("CPU: %s\n", model_name);
+ } else {
+ printf("CPU: Error model_name not found.\n");
+ }
+
+ fclose(file);
+ return 0;
+}
diff --git a/src/modules/cpu/cpu.h b/src/modules/cpu/cpu.h
new file mode 100644
index 0000000..bff5794
--- /dev/null
+++ b/src/modules/cpu/cpu.h
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+#ifndef CPU_H
+#define CPU_H
+
+int cpu(void);
+
+#endif // CPU_H