Files
fastfetch/src/detection/memory/memory_bsd.c
T
Linus Dierheimer b8656d5e12 Fix build on BSD
2022-09-29 12:24:00 +02:00

35 lines
940 B
C

#include "memory.h"
#include "common/sysctl.h"
static void detectRam(FFMemoryStorage* ram)
{
uint32_t pageSize = (uint32_t) ffSysctlGetInt("hw.pagesize", 0);
if(pageSize == 0)
{
ffStrbufAppendS(&ram->error, "Failed to read hw.pagesize");
return;
}
ram->bytesTotal = (uint64_t) ffSysctlGetInt64("vm.stats.vm.v_page_count", 0) * pageSize;
if(ram->bytesTotal == 0)
{
ffStrbufAppendS(&ram->error, "Failed to read vm.stats.vm.v_page_count");
return;
}
ram->bytesUsed = ram->bytesTotal
- (uint64_t) ffSysctlGetInt64("vm.stats.vm.v_free_count", 0) * pageSize
- (uint64_t) ffSysctlGetInt64("vm.stats.vm.v_inactive_count", 0) * pageSize
;
}
static void detectSwap(FFMemoryStorage* swap)
{
ffStrbufAppendS(&swap->error, "Not implemented");
}
void ffDetectMemoryImpl(FFMemoryResult* memory)
{
detectRam(&memory->ram);
detectSwap(&memory->swap);
}