ram: Refactor on OpenBSD

Fixes up overly complicated lines, by splitting up logic
This commit is contained in:
drkhsh 2022-10-28 00:13:12 +02:00
parent d7ea986299
commit 826a5dc862
1 changed files with 17 additions and 23 deletions

View File

@ -107,41 +107,37 @@
struct uvmexp uvmexp; struct uvmexp uvmexp;
int free_pages; int free_pages;
if (load_uvmexp(&uvmexp)) { if (!load_uvmexp(&uvmexp))
return NULL;
free_pages = uvmexp.npages - uvmexp.active; free_pages = uvmexp.npages - uvmexp.active;
return fmt_human(pagetok(free_pages, uvmexp.pageshift) * return fmt_human(pagetok(free_pages, uvmexp.pageshift) *
1024, 1024); 1024, 1024);
} }
return NULL;
}
const char * const char *
ram_perc(const char *unused) ram_perc(const char *unused)
{ {
struct uvmexp uvmexp; struct uvmexp uvmexp;
int percent; int percent;
if (load_uvmexp(&uvmexp)) { if (!load_uvmexp(&uvmexp))
return NULL;
percent = uvmexp.active * 100 / uvmexp.npages; percent = uvmexp.active * 100 / uvmexp.npages;
return bprintf("%d", percent); return bprintf("%d", percent);
} }
return NULL;
}
const char * const char *
ram_total(const char *unused) ram_total(const char *unused)
{ {
struct uvmexp uvmexp; struct uvmexp uvmexp;
if (load_uvmexp(&uvmexp)) { if (!load_uvmexp(&uvmexp))
return fmt_human(pagetok(uvmexp.npages,
uvmexp.pageshift) * 1024,
1024);
}
return NULL; return NULL;
return fmt_human(pagetok(uvmexp.npages,
uvmexp.pageshift) * 1024, 1024);
} }
const char * const char *
@ -149,13 +145,11 @@
{ {
struct uvmexp uvmexp; struct uvmexp uvmexp;
if (load_uvmexp(&uvmexp)) { if (!load_uvmexp(&uvmexp))
return fmt_human(pagetok(uvmexp.active,
uvmexp.pageshift) * 1024,
1024);
}
return NULL; return NULL;
return fmt_human(pagetok(uvmexp.active,
uvmexp.pageshift) * 1024, 1024);
} }
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
#include <sys/sysctl.h> #include <sys/sysctl.h>