GetMem fixed

This commit is contained in:
Your Name 2024-01-05 23:07:26 +03:00
parent 0bb1464704
commit c30ef2f523
2 changed files with 5 additions and 4 deletions

BIN
kfetch

Binary file not shown.

View File

@ -186,19 +186,20 @@ int GetMem(const char *title, const FETCH fetch) {
if (fp == NULL)
return 1;
off_t free = 0, total = 0;
if (fscanf(fp, "MemTotal: %lu kB\nMemFree: %lu kB", &total, &free) < 0)
off_t free = 0, total = 0, cached = 0, buffer = 0, unused = 0;
if (fscanf(fp, "MemTotal: %lu kB\nMemFree: %lu kB\nMemAvailable: %lu kB\nBuffers: %lu kB\nCached: %lu kB", &total, &free, &unused, &buffer, &cached) < 0)
return 1;
fclose(fp);
off_t used = (total - (cached + free + buffer)) / 1024;
#ifdef PRINT_USED_AND_TOTAL_MEM
printf("%s%s%s%lumb / %lumb", fetch.color, title, fetch.font_color, (uintmax_t)(total - free) / 1024, (uintmax_t)total / 1024);
printf("%s%s%s%lumb / %lumb", fetch.color, title, fetch.font_color, (uintmax_t)used, (uintmax_t)total / 1024);
#elif PRINT_TOTALMEM
printf("%s%s%s%lumb", fetch.color, title, fetch.font_color, (uintmax_t)total / 1024);
#else
printf("%s%s%s%lumb", fetch.color, title, fetch.font_color, (uintmax_t)(total - free) / 1024);
printf("%s%s%s%lumb", fetch.color, title, fetch.font_color, (uintmax_t)used);
#endif