From 9bfaf4dd363429757754d9934ca38fad4ef7dc0a Mon Sep 17 00:00:00 2001 From: Anser Date: Thu, 13 Aug 2026 15:28:47 +0200 Subject: changed get_os to get_kernel, it now uses the system_info_t struct to store and display the kernel information. Same with get_cpu. --- src/sysinfo.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'src/sysinfo.c') diff --git a/src/sysinfo.c b/src/sysinfo.c index bb7f20d..f402741 100644 --- a/src/sysinfo.c +++ b/src/sysinfo.c @@ -1,12 +1,14 @@ #include "../include/cfetch.h" +#include #include -void get_os(system_info_t *info) { +void get_kernel(system_info_t *info) { #ifdef __linux__ struct utsname u; if (uname(&u) == 0) { - size_t length = printf("OS: %s %s %s %s\n", u.sysname, u.release, u.version, u.machine); + snprintf(info->kernel, sizeof(info->kernel), "%.30s %.30s", u.sysname, u.release); + printf("Kernel: %s\n", info->kernel); } else { perror("Error while accessing uname"); return; @@ -20,39 +22,29 @@ void get_cpu(system_info_t *info) { //check file existence if (!file) { - perror("/proc/cpuinfo not found"); + snprintf(info->cpu, sizeof(info->cpu), "Unknown"); return; } char line[256]; - char *model_name = NULL; + char cpu_name[256] = "Unknown"; + char *colon = 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 : + colon = 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; - } + if (colon != NULL) { + snprintf(info->cpu, sizeof(info->cpu), "%s", trim_whitespace(colon)); - } else { - printf("CPU: Error model_name not found.\n"); - } + printf("CPU: %s\n", info->cpu); + } fclose(file); return; -- cgit v1.2.3