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