free already has an -m option to get value in mebibytes. Using that instead of calculating it in the code.
This commit is contained in:
parent
9eb6df1eb4
commit
8d53fe306e
1 changed files with 2 additions and 12 deletions
14
uwufetch.c
14
uwufetch.c
|
@ -456,21 +456,11 @@ void get_info()
|
|||
#ifndef __CYGWIN__
|
||||
FILE *meminfo;
|
||||
|
||||
meminfo = popen("LANG=EN_us free 2> /dev/null", "r");
|
||||
meminfo = popen("LANG=EN_us free -m 2> /dev/null", "r");
|
||||
while (fgets(line, sizeof(line), meminfo))
|
||||
{
|
||||
// free command prints like this: "Mem:" total used free shared buff/cache available
|
||||
if (sscanf(line, "Mem: %d %d", &ram_total, &ram_used))
|
||||
{
|
||||
// convert to mebibytes
|
||||
if (ram_total > 0 && ram_used > 0)
|
||||
{
|
||||
// data is in kibibytes
|
||||
ram_total /= 1024;
|
||||
ram_used /= 1024;
|
||||
break;
|
||||
}
|
||||
}
|
||||
sscanf(line, "Mem: %d %d", &ram_total, &ram_used);
|
||||
}
|
||||
fclose(meminfo);
|
||||
#else
|
||||
|
|
Loading…
Reference in a new issue