From 537230def11fddb3a63f8b4d0bf9b5d64b96e6d0 Mon Sep 17 00:00:00 2001 From: Anser Date: Fri, 14 Aug 2026 10:43:03 +0200 Subject: Changed codingstyle to C kernel style. Print of Systeminformation is now its own function all systeminformation is now stored inside the struct --- src/sysinfo.c | 118 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 59 insertions(+), 59 deletions(-) (limited to 'src/sysinfo.c') diff --git a/src/sysinfo.c b/src/sysinfo.c index f402741..eddaa02 100644 --- a/src/sysinfo.c +++ b/src/sysinfo.c @@ -2,75 +2,75 @@ #include #include -void get_kernel(system_info_t *info) { +void get_kernel(struct system_info_t *info) +{ #ifdef __linux__ - struct utsname u; - - if (uname(&u) == 0) { - 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; - } + struct utsname u; + + if (uname(&u) == 0) { + snprintf(info->kernel, sizeof(info->kernel), "%.30s %.30s", u.sysname, u.release); + } else { + perror("Error while accessing uname"); + return; + } #endif - return; + return; } -void get_cpu(system_info_t *info) { - FILE* file = fopen("/proc/cpuinfo", "r"); - - //check file existence - if (!file) { - snprintf(info->cpu, sizeof(info->cpu), "Unknown"); - return; - } - - char line[256]; - 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) { - colon = strchr(p, ':') + 1; //skip : - break; - } - } - - if (colon != NULL) { - snprintf(info->cpu, sizeof(info->cpu), "%s", trim_whitespace(colon)); - - printf("CPU: %s\n", info->cpu); - } - - fclose(file); - return; +void get_cpu(struct system_info_t *info) +{ + FILE* file = fopen("/proc/cpuinfo", "r"); + + //check file existence + if (!file) { + snprintf(info->cpu, sizeof(info->cpu), "Unknown"); + return; + } + + char line[256]; + char *cpu_name = NULL; + + //read per line + while (fgets(line, sizeof(line), file)) { + char* p = strstr(line, "model name"); + + if (p != NULL) { + cpu_name = strchr(p, ':') + 1; //skip : + break; + } + } + + if (cpu_name != NULL) { + snprintf(info->cpu, sizeof(info->cpu), "%s", trim_whitespace(cpu_name)); + } + + fclose(file); + return; } -void get_memory(system_info_t *info) { - FILE *file = fopen("/proc/meminfo", "r"); +void get_memory(struct system_info_t *info) +{ + FILE *file = fopen("/proc/meminfo", "r"); - if (!file) { - perror("Error fopen meminfo"); - return; - } + if (!file) { + snprintf(info->memory, sizeof(info->memory), "Unknown"); + return; + } - char line[256]; - long total = 0; - long available = 0; + char line[256]; + long total = 0; + long available = 0; - // read per line - while (fgets(line, sizeof(line), file)) { - if (sscanf(line, "MemTotal: %ld kB", &total) == 1) continue; - if (sscanf(line, "MemAvailable: %ld kB", &available) == 1) continue; - } + // read per line + while (fgets(line, sizeof(line), file)) { + if (sscanf(line, "MemTotal: %ld kB", &total) == 1) continue; + if (sscanf(line, "MemAvailable: %ld kB", &available) == 1) continue; + } - fclose(file); + fclose(file); - printf("Memory: %.2f GB / %.2f GB\n", (total - available) / (1024.0 * 1024.0), total / (1024.0 * 1024.0)); + snprintf(info->memory, sizeof(info->memory), "Memory %.2f GB / %.2f GB", + (total - available) / (1024.0 * 1024.0), total / (1024.0 * 1024.0)); - return; + return; } -- cgit v1.2.3