Skip to content

Commit

Permalink
Unbreak reading memory usage on Linux
Browse files Browse the repository at this point in the history
This never should have worked.
  • Loading branch information
tbodt committed Jul 6, 2019
1 parent c897ca4 commit 668fbe7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions platform/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ static void read_proc_line(const char *file, const char *name, char *buf) {
if (f == NULL) ERRNO_DIE(file);
do {
fgets(buf, 1234, f);
} while (strncmp(name, buf, strlen(name)) != 0 || buf[strlen(name)] != ' ');
if (feof(f))
die("could not find proc line %s", name);
} while (!(strncmp(name, buf, strlen(name)) == 0 && buf[strlen(name)] == ':'));
fclose(f);
}

Expand All @@ -29,10 +31,10 @@ struct mem_usage get_mem_usage() {
sscanf(buf, "MemTotal: %"PRIu64" kB\n", &usage.total);
read_proc_line("/proc/meminfo", "MemFree", buf);
sscanf(buf, "MemFree: %"PRIu64" kB\n", &usage.free);
read_proc_line("/proc/meminfo", "MemActive", buf);
sscanf(buf, "MemActive: %"PRIu64" kB\n", &usage.active);
read_proc_line("/proc/meminfo", "MemInactive", buf);
sscanf(buf, "MemInactive: %"PRIu64" kB\n", &usage.inactive);
read_proc_line("/proc/meminfo", "Active", buf);
sscanf(buf, "Active: %"PRIu64" kB\n", &usage.active);
read_proc_line("/proc/meminfo", "Inactive", buf);
sscanf(buf, "Inactive: %"PRIu64" kB\n", &usage.inactive);

return usage;
}

0 comments on commit 668fbe7

Please sign in to comment.