aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnser <rostgans@tutamail.com>2026-08-19 14:36:25 +0200
committerAnser <rostgans@tutamail.com>2026-08-19 21:49:11 +0200
commitdb877ae6cf1a3b24fd33ea9c5b56967d262e050c (patch)
tree0070fcda463ec9769973461ca0b1e86b8bbd3569
parent0434286445e8f5e62c818ef65f73c42433195e0c (diff)
fix: set default value in all functions
-rw-r--r--src/sysinfo.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/src/sysinfo.c b/src/sysinfo.c
index 5142197..cfab2e1 100644
--- a/src/sysinfo.c
+++ b/src/sysinfo.c
@@ -23,31 +23,24 @@
void get_kernel(struct system_info_t *info)
{
-#ifdef __linux__
struct utsname u;
+ snprintf(info->kernel, sizeof(info->kernel), "Unknown");
- 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;
+ if (uname(&u) != 0) return;
+
+ snprintf(info->kernel, sizeof(info->kernel), "%.30s %.30s", u.sysname, u.release);
}
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;
+ snprintf(info->cpu, sizeof(info->cpu), "Unknown");
+
+ FILE* file = fopen("/proc/cpuinfo", "r");
+ if (!file) return; // check pointer
+
+
//read per line
while (fgets(line, sizeof(line), file)) {
@@ -69,16 +62,14 @@ void get_cpu(struct system_info_t *info)
void get_memory(struct system_info_t *info)
{
- FILE *file = fopen("/proc/meminfo", "r");
-
- if (!file) {
- snprintf(info->memory, sizeof(info->memory), "Unknown");
- return;
- }
-
char line[256];
long total = 0;
long available = 0;
+ snprintf(info->memory, sizeof(info->memory), "Unknown");
+
+ FILE *file = fopen("/proc/meminfo", "r");
+ if (!file) return;
+
// read per line
while (fgets(line, sizeof(line), file)) {
@@ -135,15 +126,13 @@ void get_os_release(struct system_info_t *info)
char id[64] = { 0 };
char version_id[64] = { 0 };
char pretty_name[64] = { 0 };
+ snprintf(info->distro, sizeof(info->distro), "Unknown");
file = fopen("/etc/os-release", "r");
if (!file) {
file = fopen("/usr/lib/os-release", "r");
}
- if (!file) {
- snprintf(info->distro, sizeof(info->distro), "Unknown");
- return;
- }
+ if (!file) return;
// get ID, PRETTY_NAME, VERSION_ID
while (fgets(line, sizeof(line), file)) {