diff options
Diffstat (limited to 'src/memory.c')
| -rw-r--r-- | src/memory.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/memory.c b/src/memory.c new file mode 100644 index 0000000..9e880d2 --- /dev/null +++ b/src/memory.c @@ -0,0 +1,26 @@ +#include "../include/cfetch.h" + +void get_memory(system_info_t *info) { + FILE *file = fopen("/proc/meminfo", "r"); + + if (!file) { + perror("Error fopen meminfo"); + return; + } + + 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; + } + + fclose(file); + + printf("Memory: %.2f GB / %.2f GB\n", (total - available) / (1024.0 * 1024.0), total / (1024.0 * 1024.0)); + + return; +} |
