rewind stream instead of opening a new one

This commit is contained in:
Robinhuett 2018-11-09 00:17:30 +01:00
parent ac0963c608
commit 6b62079d8a

View File

@ -25,8 +25,7 @@ void waybar::modules::Memory::parseMeminfo()
int memtotal, memfree, memavail, membuffer, memcache;
FILE* info = fopen("/proc/meminfo","r");
if(fscanf (info, "MemTotal: %d kB MemFree: %d kB Buffers: %d kB Cached: %d kB",&memtotal, &memfree, &membuffer, &memcache) < 4) { // Old meminfo format
fclose(info);
info = fopen("/proc/meminfo","r");
rewind(info);
if(fscanf(info, "MemTotal: %d kB MemFree: %d kB MemAvailable: %d kB Buffers: %d kB Cached: %d kB",&memtotal, &memfree, &memavail, &membuffer, &memcache) < 5) { // Current meminfo format
memtotal_ = -1;
memfree_ = -1;