aboutsummaryrefslogtreecommitdiff
path: root/src/sysinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sysinfo.c')
-rw-r--r--src/sysinfo.c32
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;