diff options
| author | Anser <rostgans@tutamail.com> | 2026-08-13 15:28:47 +0200 |
|---|---|---|
| committer | Anser <rostgans@tutamail.com> | 2026-08-14 10:44:28 +0200 |
| commit | 9bfaf4dd363429757754d9934ca38fad4ef7dc0a (patch) | |
| tree | c13a7148dfd96178481744368dd0d29a6bdc033d /src/sysinfo.c | |
| parent | d195f0a76a3ce64761958f7d33ccbdbac3844fec (diff) | |
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.
Diffstat (limited to 'src/sysinfo.c')
| -rw-r--r-- | src/sysinfo.c | 32 |
1 files changed, 12 insertions, 20 deletions
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 <stdio.h> #include <sys/utsname.h> -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; |
