diff options
| author | Anser <rostgans@tutamail.com> | 2026-07-07 00:16:45 +0200 |
|---|---|---|
| committer | Anser <rostgans@tutamail.com> | 2026-07-31 11:12:27 +0200 |
| commit | 186b3f148107f8a3590f8de79a389e84b0005082 (patch) | |
| tree | 625770899babaa15a25193bd854a1ef87b1b8710 /src/modules/cpu/cpu.c | |
| parent | 8ac7197b890e4e18fda8c5a4b8adb2228f0b7be5 (diff) | |
added cpu info.... but needs string parsing for whitespace
Diffstat (limited to 'src/modules/cpu/cpu.c')
| -rw-r--r-- | src/modules/cpu/cpu.c | 36 |
1 files changed, 36 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; +} |
