mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
Platform: detect system page size
This commit is contained in:
@@ -22,6 +22,8 @@ typedef struct FFPlatform {
|
||||
FFstrbuf systemVersion;
|
||||
FFstrbuf systemArchitecture;
|
||||
FFstrbuf systemDisplayVersion;
|
||||
|
||||
uint32_t pageSize;
|
||||
} FFPlatform;
|
||||
|
||||
void ffPlatformInit(FFPlatform* platform);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <libproc.h>
|
||||
#include <sys/sysctl.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
@@ -153,6 +154,16 @@ static void getUserShell(FFPlatform* platform, const struct passwd* pwd)
|
||||
ffStrbufAppendS(&platform->userShell, shell);
|
||||
}
|
||||
|
||||
static void getPageSize(FFPlatform* platform)
|
||||
{
|
||||
#if defined(__FreeBSD__) || defined(__APPLE__)
|
||||
size_t length = sizeof(platform->pageSize);
|
||||
sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &platform->pageSize, &length, NULL, 0);
|
||||
#else
|
||||
platform->pageSize = (uint32_t) sysconf(_SC_PAGESIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ffPlatformInitImpl(FFPlatform* platform)
|
||||
{
|
||||
struct passwd* pwd = getpwuid(getuid());
|
||||
@@ -176,4 +187,6 @@ void ffPlatformInitImpl(FFPlatform* platform)
|
||||
ffStrbufAppendS(&platform->systemVersion, uts.version);
|
||||
ffStrbufAppendS(&platform->systemArchitecture, uts.machine);
|
||||
ffStrbufInit(&platform->systemDisplayVersion);
|
||||
|
||||
getPageSize(platform);
|
||||
}
|
||||
|
||||
@@ -183,9 +183,9 @@ static void getSystemReleaseAndVersion(FFPlatform* platform)
|
||||
}
|
||||
}
|
||||
|
||||
static void getSystemArchitecture(FFPlatform* platform)
|
||||
static void getSystemArchitectureAndPageSize(FFPlatform* platform)
|
||||
{
|
||||
SYSTEM_INFO sysInfo = {0};
|
||||
SYSTEM_INFO sysInfo;
|
||||
GetNativeSystemInfo(&sysInfo);
|
||||
|
||||
switch(sysInfo.wProcessorArchitecture)
|
||||
@@ -215,6 +215,8 @@ static void getSystemArchitecture(FFPlatform* platform)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
platform->pageSize = sysInfo.dwPageSize;
|
||||
}
|
||||
|
||||
void ffPlatformInitImpl(FFPlatform* platform)
|
||||
@@ -230,5 +232,5 @@ void ffPlatformInitImpl(FFPlatform* platform)
|
||||
getUserShell(platform);
|
||||
|
||||
getSystemReleaseAndVersion(platform);
|
||||
getSystemArchitecture(platform);
|
||||
getSystemArchitectureAndPageSize(platform);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user