From eb6f986361713d6ce47c6d4572bb24d9f6207ddf Mon Sep 17 00:00:00 2001 From: Anser Date: Tue, 11 Aug 2026 00:18:57 +0200 Subject: TOBESQUISHED: safe in reconstruction of the codes layout and rework of information handeling also ascii art printing --- src/cpu.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/cpu.c (limited to 'src/cpu.c') diff --git a/src/cpu.c b/src/cpu.c new file mode 100644 index 0000000..c45cd9e --- /dev/null +++ b/src/cpu.c @@ -0,0 +1,44 @@ +#include "../include/cfetch.h" + +void get_cpu(system_info_t *info) { + FILE* file = fopen("/proc/cpuinfo", "r"); + + //check file existence + if (!file) { + perror("/proc/cpuinfo not found"); + return; + } + + 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; +} -- cgit v1.2.3