Skip to content

Commit 4139165

Browse files
committed
parse_meminfo: explain buffer size choice and drop absolute path
main() makes sure that we already are in /proc, and we use relative paths everywhere else, so follow suite.
1 parent 0f7b340 commit 4139165

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

meminfo.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@ static long available_guesstimate(const char* buf)
5656
meminfo_t parse_meminfo()
5757
{
5858
static FILE* fd;
59+
// On Linux 5.3, "wc -c /proc/meminfo" counts 1391 bytes.
60+
// 8192 should be enough for the foreseeable future.
5961
static char buf[8192];
6062
static int guesstimate_warned = 0;
6163
meminfo_t m;
6264

6365
if (fd == NULL)
64-
fd = fopen("/proc/meminfo", "r");
66+
// main() makes sure that we are in /proc
67+
fd = fopen("meminfo", "r");
6568
if (fd == NULL) {
6669
fatal(102, "could not open /proc/meminfo: %s\n", strerror(errno));
6770
}

0 commit comments

Comments
 (0)