Kernel: code refactor

This commit is contained in:
Carter Li 2024-07-02 10:12:26 +08:00 committed by 李通洲
parent 2cd421fc2e
commit a749014e7c
No known key found for this signature in database
GPG Key ID: 269AD4F5325A22A3
19 changed files with 180 additions and 157 deletions

View File

@ -25,7 +25,7 @@ const char* ffDetectMemory(FFMemoryResult* ram)
+ vmstat.compressor_page_count
- vmstat.purgeable_count
- vmstat.external_page_count
) * instance.state.platform.pageSize;
) * instance.state.platform.sysinfo.pageSize;
return NULL;
}

View File

@ -12,7 +12,7 @@ const char* ffDetectMemory(FFMemoryResult* ram)
+ ffSysctlGetInt("vm.stats.vm.v_inactive_count", 0)
+ ffSysctlGetInt("vm.stats.vm.v_cache_count", 0);
ram->bytesUsed = ram->bytesTotal - (uint64_t) pagesFree * instance.state.platform.pageSize;
ram->bytesUsed = ram->bytesTotal - (uint64_t) pagesFree * instance.state.platform.sysinfo.pageSize;
return NULL;
}

View File

@ -23,11 +23,11 @@ const char* ffDetectMemory(FFMemoryResult* ram)
{
kstat_named_t* kn = kstat_data_lookup(ks, "pagestotal");
ram->bytesTotal = kn->value.ui64 * instance.state.platform.pageSize;
ram->bytesTotal = kn->value.ui64 * instance.state.platform.sysinfo.pageSize;
}
{
kstat_named_t* kn = kstat_data_lookup(ks, "pagesfree");
ram->bytesUsed = ram->bytesTotal - kn->value.ui64 * instance.state.platform.pageSize;
ram->bytesUsed = ram->bytesTotal - kn->value.ui64 * instance.state.platform.sysinfo.pageSize;
}
return NULL;

View File

@ -25,8 +25,8 @@ const char* ffDetectSwap(FFSwapResult* swap)
swap->bytesTotal += (uint64_t) xsw.xsw_nblks;
}
swap->bytesUsed *= instance.state.platform.pageSize;
swap->bytesTotal *= instance.state.platform.pageSize;
swap->bytesUsed *= instance.state.platform.sysinfo.pageSize;
swap->bytesTotal *= instance.state.platform.sysinfo.pageSize;
return NULL;
}

View File

@ -26,8 +26,8 @@ const char* ffDetectSwap(FFSwapResult* swap)
swap->bytesUsed += (uint64_t) table->swt_ent[i].ste_free;
}
swap->bytesUsed = swap->bytesTotal - swap->bytesUsed;
swap->bytesTotal *= instance.state.platform.pageSize;
swap->bytesUsed *= instance.state.platform.pageSize;
swap->bytesTotal *= instance.state.platform.sysinfo.pageSize;
swap->bytesUsed *= instance.state.platform.sysinfo.pageSize;
return NULL;
}

View File

@ -13,7 +13,7 @@ const char* ffDetectSwap(FFSwapResult* swap)
if(!NT_SUCCESS(NtQuerySystemInformation(SystemPagefileInformation, pstart, size, &size)))
return "NtQuerySystemInformation(SystemPagefileInformation, size) failed";
uint32_t pageSize = instance.state.platform.pageSize;
uint32_t pageSize = instance.state.platform.sysinfo.pageSize;
swap->bytesUsed = (uint64_t)pstart->TotalUsed * pageSize;
swap->bytesTotal = (uint64_t)pstart->CurrentSize * pageSize;

View File

@ -500,7 +500,7 @@ static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version)
return getExeVersionGeneral(exe, version);
}
static bool getTerminalVersionPtyxis(FF_MAYBE_UNUSED FFstrbuf* exe, FFstrbuf* version)
FF_MAYBE_UNUSED static bool getTerminalVersionPtyxis(FF_MAYBE_UNUSED FFstrbuf* exe, FFstrbuf* version)
{
if(ffProcessAppendStdOut(version, (char* const[]) {
"ptyxis",

View File

@ -20,43 +20,61 @@
#define FF_ARCHITECTURE "unknown"
#endif
#if defined(__linux__)
#define FF_SYSNAME "Linux"
#elif defined(__FreeBSD__)
#define FF_SYSNAME "FreeBSD"
#elif defined(__APPLE__)
#define FF_SYSNAME "Darwin"
#elif defined(_WIN32)
#define FF_SYSNAME "WIN32"
#elif defined(__sun)
#define FF_SYSNAME "SunOS"
#else
#define FF_SYSNAME "unknown"
#endif
#define FF_STR_INDIR(x) #x
#define FF_STR(x) FF_STR_INDIR(x)
void ffDetectVersion(FFVersionResult* version)
{
version->projectName = FASTFETCH_PROJECT_NAME;
version->architecture = FF_ARCHITECTURE;
version->version = FASTFETCH_PROJECT_VERSION;
version->versionTweak = FASTFETCH_PROJECT_VERSION_TWEAK;
version->cmakeBuiltType = FASTFETCH_PROJECT_CMAKE_BUILD_TYPE;
version->compileTime = __DATE__ ", " __TIME__;
FFVersionResult ffVersionResult = {
.projectName = FASTFETCH_PROJECT_NAME,
.sysName = FF_SYSNAME,
.architecture = FF_ARCHITECTURE,
.version = FASTFETCH_PROJECT_VERSION,
.versionTweak = FASTFETCH_PROJECT_VERSION_TWEAK,
.cmakeBuiltType = FASTFETCH_PROJECT_CMAKE_BUILD_TYPE,
.compileTime = __DATE__ ", " __TIME__,
.compiler =
#ifdef __clang__
version->compiler =
#ifdef _MSC_VER
"clang-cl " ;
#elif defined(__APPLE__) && defined(__apple_build_version__)
"Apple clang "
#else
"clang "
#endif
#ifdef _MSC_VER
"clang-cl " ;
#elif defined(__APPLE__) && defined(__apple_build_version__)
"Apple clang "
#else
"clang "
#endif
FF_STR(__clang_major__) "." FF_STR(__clang_minor__) "." FF_STR(__clang_patchlevel__)
FF_STR(__clang_major__) "." FF_STR(__clang_minor__) "." FF_STR(__clang_patchlevel__)
#if defined(__APPLE__) && defined(__apple_build_version__)
" (" FF_STR(__apple_build_version__) ")"
#endif
;
#if defined(__APPLE__) && defined(__apple_build_version__)
" (" FF_STR(__apple_build_version__) ")"
#endif
,
#elif defined(__GNUC__)
version->compiler = "gcc " FF_STR(__GNUC__) "." FF_STR(__GNUC_MINOR__) "." FF_STR(__GNUC_PATCHLEVEL__);
"gcc " FF_STR(__GNUC__) "." FF_STR(__GNUC_MINOR__) "." FF_STR(__GNUC_PATCHLEVEL__),
#elif defined(_MSC_VER)
version->compiler = "msvc " FF_STR(_MSC_VER);
"msvc " FF_STR(_MSC_VER),
#else
version->compiler = "unknown";
"unknown",
#endif
.debugMode =
#ifndef NDEBUG
version->debugMode = true;
true,
#else
version->debugMode = false;
false,
#endif
}
};

View File

@ -5,6 +5,7 @@
typedef struct FFVersionResult
{
const char* projectName;
const char* sysName;
const char* architecture;
const char* version;
const char* versionTweak;
@ -14,4 +15,4 @@ typedef struct FFVersionResult
bool debugMode;
} FFVersionResult;
void ffDetectVersion(FFVersionResult* version);
extern FFVersionResult ffVersionResult;

View File

@ -501,9 +501,8 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val
static void printVersion()
{
FFVersionResult result = {};
ffDetectVersion(&result);
printf("%s %s%s%s (%s)\n", result.projectName, result.version, result.versionTweak, result.debugMode ? "-debug" : "", result.architecture);
FFVersionResult* result = &ffVersionResult;
printf("%s %s%s%s (%s)\n", result->projectName, result->version, result->versionTweak, result->debugMode ? "-debug" : "", result->architecture);
}
static void parseCommand(FFdata* data, char* key, char* value)

View File

@ -340,7 +340,7 @@ static const FFlogo* logoGetBuiltinDetected(FFLogoSize size)
if(logo != NULL)
return logo;
logo = logoGetBuiltin(&instance.state.platform.systemName, size);
logo = logoGetBuiltin(&instance.state.platform.sysinfo.name, size);
if(logo != NULL)
return logo;

View File

@ -3,29 +3,32 @@
#include "modules/kernel/kernel.h"
#include "util/stringUtils.h"
#define FF_KERNEL_NUM_FORMAT_ARGS 5
#define FF_KERNEL_NUM_FORMAT_ARGS 6
void ffPrintKernel(FFKernelOptions* options)
{
const FFPlatform* platform = &instance.state.platform;
const FFPlatformSysinfo* info = &instance.state.platform.sysinfo;
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_KERNEL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
printf("%s %s", platform->systemName.chars, platform->systemRelease.chars);
printf("%s %s", info->name.chars, info->release.chars);
if(platform->systemDisplayVersion.length > 0)
printf(" (%s)\n", platform->systemDisplayVersion.chars);
if(info->displayVersion.length > 0)
printf(" (%s)\n", info->displayVersion.chars);
else
putchar('\n');
}
else
{
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
ffParseSize(info->pageSize, &str);
FF_PRINT_FORMAT_CHECKED(FF_KERNEL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_KERNEL_NUM_FORMAT_ARGS, ((FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemName, "sysname"},
{FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemRelease, "release"},
{FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemVersion, "version"},
{FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemArchitecture, "arch"},
{FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemDisplayVersion, "display-version"},
{FF_FORMAT_ARG_TYPE_STRBUF, &info->name, "sysname"},
{FF_FORMAT_ARG_TYPE_STRBUF, &info->release, "release"},
{FF_FORMAT_ARG_TYPE_STRBUF, &info->version, "version"},
{FF_FORMAT_ARG_TYPE_STRBUF, &info->architecture, "arch"},
{FF_FORMAT_ARG_TYPE_STRBUF, &info->displayVersion, "display-version"},
{FF_FORMAT_ARG_TYPE_STRBUF, &str, "page-size"},
}));
}
}
@ -67,12 +70,15 @@ void ffGenerateKernelJsonConfig(FFKernelOptions* options, yyjson_mut_doc* doc, y
void ffGenerateKernelJsonResult(FF_MAYBE_UNUSED FFKernelOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
const FFPlatformSysinfo* info = &instance.state.platform.sysinfo;
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "architecture", &instance.state.platform.systemArchitecture);
yyjson_mut_obj_add_strbuf(doc, obj, "name", &instance.state.platform.systemName);
yyjson_mut_obj_add_strbuf(doc, obj, "release", &instance.state.platform.systemRelease);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &instance.state.platform.systemVersion);
yyjson_mut_obj_add_strbuf(doc, obj, "displayVersion", &instance.state.platform.systemDisplayVersion);
yyjson_mut_obj_add_strbuf(doc, obj, "architecture", &info->architecture);
yyjson_mut_obj_add_strbuf(doc, obj, "name", &info->name);
yyjson_mut_obj_add_strbuf(doc, obj, "release", &info->release);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &info->version);
yyjson_mut_obj_add_strbuf(doc, obj, "displayVersion", &info->displayVersion);
yyjson_mut_obj_add_uint(doc, obj, "pageSize", info->pageSize);
}
void ffPrintKernelHelpFormat(void)
@ -83,6 +89,7 @@ void ffPrintKernelHelpFormat(void)
"Version - version",
"Architecture - arch",
"Display version - display-version",
"Page size - page-size",
}));
}

View File

@ -19,7 +19,7 @@ static void buildOutputDefault(const FFOSResult* os, FFstrbuf* result)
else if(os->id.length > 0)
ffStrbufAppend(result, &os->id);
else
ffStrbufAppend(result, &instance.state.platform.systemName);
ffStrbufAppend(result, &instance.state.platform.sysinfo.name);
//Append code name if it is missing
if(os->codename.length > 0 && !ffStrbufContainIgnCase(result, &os->codename))
@ -55,10 +55,10 @@ static void buildOutputDefault(const FFOSResult* os, FFstrbuf* result)
}
//Append architecture if it is missing
if(!ffStrbufContainIgnCase(result, &instance.state.platform.systemArchitecture))
if(!ffStrbufContainIgnCase(result, &instance.state.platform.sysinfo.architecture))
{
ffStrbufAppendC(result, ' ');
ffStrbufAppend(result, &instance.state.platform.systemArchitecture);
ffStrbufAppend(result, &instance.state.platform.sysinfo.architecture);
}
}
@ -80,10 +80,10 @@ static void buildOutputNixOS(const FFOSResult* os, FFstrbuf* result)
ffStrbufAppendC(result, ')');
}
if(instance.state.platform.systemArchitecture.length > 0)
if(instance.state.platform.sysinfo.architecture.length > 0)
{
ffStrbufAppendC(result, ' ');
ffStrbufAppend(result, &instance.state.platform.systemArchitecture);
ffStrbufAppend(result, &instance.state.platform.sysinfo.architecture);
}
}
@ -112,7 +112,7 @@ void ffPrintOS(FFOSOptions* options)
else
{
FF_PRINT_FORMAT_CHECKED(FF_OS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_OS_NUM_FORMAT_ARGS, ((FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.systemName, "sysname"},
{FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.sysinfo.name, "sysname"},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->name, "name"},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->prettyName, "pretty-name"},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->id, "id"},
@ -123,7 +123,7 @@ void ffPrintOS(FFOSOptions* options)
{FF_FORMAT_ARG_TYPE_STRBUF, &os->versionID, "version-id"},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->codename, "codename"},
{FF_FORMAT_ARG_TYPE_STRBUF, &os->buildID, "build-id"},
{FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.systemArchitecture, "arch"}
{FF_FORMAT_ARG_TYPE_STRBUF, &instance.state.platform.sysinfo.architecture, "arch"}
}));
}
}

View File

@ -176,7 +176,6 @@ void ffGenerateTitleJsonResult(FF_MAYBE_UNUSED FFTitleOptions* options, yyjson_m
yyjson_mut_obj_add_strbuf(doc, obj, "homeDir", &instance.state.platform.homeDir);
yyjson_mut_obj_add_strbuf(doc, obj, "exePath", &instance.state.platform.exePath);
yyjson_mut_obj_add_strbuf(doc, obj, "userShell", &instance.state.platform.userShell);
yyjson_mut_obj_add_uint(doc, obj, "pageSize", instance.state.platform.pageSize);
}
void ffPrintTitleHelpFormat(void)

View File

@ -5,17 +5,16 @@
#include "modules/version/version.h"
#include "util/stringUtils.h"
#define FF_VERSION_NUM_FORMAT_ARGS 9
#define FF_VERSION_NUM_FORMAT_ARGS 10
void ffPrintVersion(FFVersionOptions* options)
{
FFVersionResult result;
ffDetectVersion(&result);
FFVersionResult* result = &ffVersionResult;
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_VERSION_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
printf("%s %s%s%s (%s)\n", result.projectName, result.version, result.versionTweak, result.debugMode ? "-debug" : "", result.architecture);
printf("%s %s%s%s (%s)\n", result->projectName, result->version, result->versionTweak, result->debugMode ? "-debug" : "", result->architecture);
}
else
{
@ -32,14 +31,15 @@ void ffPrintVersion(FFVersionOptions* options)
}
FF_PRINT_FORMAT_CHECKED(FF_VERSION_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_VERSION_NUM_FORMAT_ARGS, ((FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRING, result.projectName, "project-name"},
{FF_FORMAT_ARG_TYPE_STRING, result.version, "version"},
{FF_FORMAT_ARG_TYPE_STRING, result.versionTweak, "version-tweak"},
{FF_FORMAT_ARG_TYPE_STRING, result.debugMode ? "debug" : "release", "build-type"},
{FF_FORMAT_ARG_TYPE_STRING, result.architecture, "arch"},
{FF_FORMAT_ARG_TYPE_STRING, result.cmakeBuiltType, "cmake-built-type"},
{FF_FORMAT_ARG_TYPE_STRING, result.compileTime, "compile-time"},
{FF_FORMAT_ARG_TYPE_STRING, result.compiler, "compiler"},
{FF_FORMAT_ARG_TYPE_STRING, result->projectName, "project-name"},
{FF_FORMAT_ARG_TYPE_STRING, result->version, "version"},
{FF_FORMAT_ARG_TYPE_STRING, result->versionTweak, "version-tweak"},
{FF_FORMAT_ARG_TYPE_STRING, result->debugMode ? "debug" : "release", "build-type"},
{FF_FORMAT_ARG_TYPE_STRING, result->sysName, "sysname"},
{FF_FORMAT_ARG_TYPE_STRING, result->architecture, "arch"},
{FF_FORMAT_ARG_TYPE_STRING, result->cmakeBuiltType, "cmake-built-type"},
{FF_FORMAT_ARG_TYPE_STRING, result->compileTime, "compile-time"},
{FF_FORMAT_ARG_TYPE_STRING, result->compiler, "compiler"},
{FF_FORMAT_ARG_TYPE_STRBUF, &buf, "libc-used"},
}));
}
@ -82,18 +82,18 @@ void ffGenerateVersionJsonConfig(FFVersionOptions* options, yyjson_mut_doc* doc,
void ffGenerateVersionJsonResult(FF_MAYBE_UNUSED FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FFVersionResult result;
ffDetectVersion(&result);
FFVersionResult* result = &ffVersionResult;
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_str(doc, obj, "projectName", result.projectName);
yyjson_mut_obj_add_str(doc, obj, "architecture", result.architecture);
yyjson_mut_obj_add_str(doc, obj, "version", result.version);
yyjson_mut_obj_add_str(doc, obj, "versionTweak", result.versionTweak);
yyjson_mut_obj_add_str(doc, obj, "cmakeBuiltType", result.cmakeBuiltType);
yyjson_mut_obj_add_str(doc, obj, "compileTime", result.compileTime);
yyjson_mut_obj_add_str(doc, obj, "compiler", result.compiler);
yyjson_mut_obj_add_bool(doc, obj, "debugMode", result.debugMode);
yyjson_mut_obj_add_str(doc, obj, "projectName", result->projectName);
yyjson_mut_obj_add_str(doc, obj, "sysName", result->sysName);
yyjson_mut_obj_add_str(doc, obj, "architecture", result->architecture);
yyjson_mut_obj_add_str(doc, obj, "version", result->version);
yyjson_mut_obj_add_str(doc, obj, "versionTweak", result->versionTweak);
yyjson_mut_obj_add_str(doc, obj, "cmakeBuiltType", result->cmakeBuiltType);
yyjson_mut_obj_add_str(doc, obj, "compileTime", result->compileTime);
yyjson_mut_obj_add_str(doc, obj, "compiler", result->compiler);
yyjson_mut_obj_add_bool(doc, obj, "debugMode", result->debugMode);
FFLibcResult libcResult;
if (ffDetectLibc(&libcResult))
@ -119,6 +119,7 @@ void ffPrintVersionHelpFormat(void)
"Version - version",
"Version tweak - version-tweak",
"Build type (debug or release) - build-type",
"System name - sysname",
"Architecture - arch",
"CMake build type when compiling (Debug, Release, RelWithDebInfo, MinSizeRel) - cmake-built-type",
"Date time when compiling - compile-time",

View File

@ -1,6 +1,7 @@
#include "FFPlatform_private.h"
#include "util/stringUtils.h"
#include "common/io/io.h"
#include "detection/version/version.h"
void ffPlatformInit(FFPlatform* platform)
{
@ -14,30 +15,20 @@ void ffPlatformInit(FFPlatform* platform)
ffStrbufInit(&platform->hostName);
ffStrbufInit(&platform->userShell);
ffStrbufInit(&platform->systemName);
ffStrbufInit(&platform->systemRelease);
ffStrbufInit(&platform->systemVersion);
ffStrbufInit(&platform->systemArchitecture);
FFPlatformSysinfo* info = &platform->sysinfo;
ffStrbufInit(&info->name);
ffStrbufInit(&info->release);
ffStrbufInit(&info->version);
ffStrbufInit(&info->architecture);
ffPlatformInitImpl(platform);
if(platform->systemName.length == 0)
{
#if defined(__linux__)
ffStrbufAppendS(&platform->systemName, "Linux");
#elif defined(__FreeBSD__)
ffStrbufAppendS(&platform->systemName, "FreeBSD");
#elif defined(__APPLE__)
ffStrbufAppendS(&platform->systemName, "Darwin");
#elif defined(_WIN32)
ffStrbufAppendS(&platform->systemName, "Windows_NT");
#else
ffStrbufAppendS(&platform->systemName, "Unknown");
#endif
}
if(info->name.length == 0)
ffStrbufSetStatic(&info->name, ffVersionResult.sysName);
if(platform->systemArchitecture.length == 0)
ffStrbufAppendS(&platform->systemArchitecture, "Unknown");
if(info->architecture.length == 0)
ffStrbufSetStatic(&info->architecture, ffVersionResult.architecture);
}
void ffPlatformDestroy(FFPlatform* platform)
@ -58,11 +49,12 @@ void ffPlatformDestroy(FFPlatform* platform)
ffStrbufDestroy(&platform->hostName);
ffStrbufDestroy(&platform->userShell);
ffStrbufDestroy(&platform->systemArchitecture);
ffStrbufDestroy(&platform->systemName);
ffStrbufDestroy(&platform->systemRelease);
ffStrbufDestroy(&platform->systemVersion);
ffStrbufDestroy(&platform->systemDisplayVersion);
FFPlatformSysinfo* info = &platform->sysinfo;
ffStrbufDestroy(&info->architecture);
ffStrbufDestroy(&info->name);
ffStrbufDestroy(&info->release);
ffStrbufDestroy(&info->version);
ffStrbufDestroy(&info->displayVersion);
}
void ffPlatformPathAddAbsolute(FFlist* dirs, const char* path)

View File

@ -3,7 +3,18 @@
#include "util/FFstrbuf.h"
#include "util/FFlist.h"
typedef struct FFPlatform {
typedef struct FFPlatformSysinfo
{
FFstrbuf name;
FFstrbuf release;
FFstrbuf version;
FFstrbuf architecture;
FFstrbuf displayVersion;
uint32_t pageSize;
} FFPlatformSysinfo;
typedef struct FFPlatform
{
FFstrbuf homeDir; // Trailing slash included
FFstrbuf cacheDir; // Trailing slash included
FFlist configDirs; // List of FFstrbuf, trailing slash included
@ -14,13 +25,7 @@ typedef struct FFPlatform {
FFstrbuf hostName;
FFstrbuf userShell;
FFstrbuf systemName;
FFstrbuf systemRelease;
FFstrbuf systemVersion;
FFstrbuf systemArchitecture;
FFstrbuf systemDisplayVersion;
uint32_t pageSize;
FFPlatformSysinfo sysinfo;
} FFPlatform;
void ffPlatformInit(FFPlatform* platform);

View File

@ -169,13 +169,19 @@ static void getUserShell(FFPlatform* platform, const struct passwd* pwd)
ffStrbufAppendS(&platform->userShell, shell);
}
static void getPageSize(FFPlatform* platform)
static void getSysinfo(FFPlatformSysinfo* info, const struct utsname* uts)
{
ffStrbufAppendS(&info->name, uts->sysname);
ffStrbufAppendS(&info->release, uts->release);
ffStrbufAppendS(&info->version, uts->version);
ffStrbufAppendS(&info->architecture, uts->machine);
ffStrbufInit(&info->displayVersion);
#if defined(__FreeBSD__) || defined(__APPLE__)
size_t length = sizeof(platform->pageSize);
sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &platform->pageSize, &length, NULL, 0);
size_t length = sizeof(info->pageSize);
sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &info->pageSize, &length, NULL, 0);
#else
platform->pageSize = (uint32_t) sysconf(_SC_PAGESIZE);
info->pageSize = (uint32_t) sysconf(_SC_PAGESIZE);
#endif
}
@ -197,11 +203,5 @@ void ffPlatformInitImpl(FFPlatform* platform)
getHostName(platform, &uts);
getUserShell(platform, pwd);
ffStrbufAppendS(&platform->systemName, uts.sysname);
ffStrbufAppendS(&platform->systemRelease, uts.release);
ffStrbufAppendS(&platform->systemVersion, uts.version);
ffStrbufAppendS(&platform->systemArchitecture, uts.machine);
ffStrbufInit(&platform->systemDisplayVersion);
getPageSize(platform);
getSysinfo(&platform->sysinfo, &uts);
}

View File

@ -159,7 +159,7 @@ static void getUserShell(FFPlatform* platform)
ffStrbufReplaceAllC(&platform->userShell, '\\', '/');
}
static void getSystemReleaseAndVersion(FFPlatform* platform)
static void getSystemReleaseAndVersion(FFPlatformSysinfo* info)
{
RTL_OSVERSIONINFOW osVersion = { .dwOSVersionInfoSize = sizeof(osVersion) };
if (!NT_SUCCESS(RtlGetVersion(&osVersion)))
@ -172,39 +172,39 @@ static void getSystemReleaseAndVersion(FFPlatform* platform)
uint32_t ubr = 0;
ffRegReadUint(hKey, L"UBR", &ubr, NULL);
ffStrbufAppendF(&platform->systemRelease,
ffStrbufAppendF(&info->release,
"%u.%u.%u.%u",
(unsigned) osVersion.dwMajorVersion,
(unsigned) osVersion.dwMinorVersion,
(unsigned) osVersion.dwBuildNumber,
(unsigned) ubr);
ffStrbufInit(&platform->systemDisplayVersion);
if(!ffRegReadStrbuf(hKey, L"DisplayVersion", &platform->systemDisplayVersion, NULL))
ffStrbufInit(&info->displayVersion);
if(!ffRegReadStrbuf(hKey, L"DisplayVersion", &info->displayVersion, NULL))
{
if (osVersion.szCSDVersion[0])
ffStrbufSetWS(&platform->systemDisplayVersion, osVersion.szCSDVersion);
ffStrbufSetWS(&info->displayVersion, osVersion.szCSDVersion);
else
ffRegReadStrbuf(hKey, L"ReleaseId", &platform->systemDisplayVersion, NULL); // For old Windows 10
ffRegReadStrbuf(hKey, L"ReleaseId", &info->displayVersion, NULL); // For old Windows 10
}
ffRegReadStrbuf(hKey, L"BuildLabEx", &platform->systemVersion, NULL);
ffRegReadStrbuf(hKey, L"BuildLabEx", &info->version, NULL);
switch (osVersion.dwPlatformId)
{
case VER_PLATFORM_WIN32s:
ffStrbufSetStatic(&platform->systemName, "WIN32s");
ffStrbufSetStatic(&info->name, "WIN32s");
break;
case VER_PLATFORM_WIN32_WINDOWS:
ffStrbufSetStatic(&platform->systemName, "WIN32_WINDOWS");
ffStrbufSetStatic(&info->name, "WIN32_WINDOWS");
break;
case VER_PLATFORM_WIN32_NT:
ffStrbufSetStatic(&platform->systemName, "WIN32_NT");
ffStrbufSetStatic(&info->name, "WIN32_NT");
break;
}
}
static void getSystemArchitectureAndPageSize(FFPlatform* platform)
static void getSystemArchitectureAndPageSize(FFPlatformSysinfo* info)
{
SYSTEM_INFO sysInfo;
GetNativeSystemInfo(&sysInfo);
@ -212,52 +212,53 @@ static void getSystemArchitectureAndPageSize(FFPlatform* platform)
switch(sysInfo.wProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_AMD64:
ffStrbufSetStatic(&platform->systemArchitecture, "x86_64");
ffStrbufSetStatic(&info->architecture, "x86_64");
break;
case PROCESSOR_ARCHITECTURE_IA64:
ffStrbufSetStatic(&platform->systemArchitecture, "ia64");
ffStrbufSetStatic(&info->architecture, "ia64");
break;
case PROCESSOR_ARCHITECTURE_INTEL:
switch (sysInfo.wProcessorLevel)
{
case 4:
ffStrbufSetStatic(&platform->systemArchitecture, "i486");
ffStrbufSetStatic(&info->architecture, "i486");
break;
case 5:
ffStrbufSetStatic(&platform->systemArchitecture, "i586");
ffStrbufSetStatic(&info->architecture, "i586");
break;
case 6:
ffStrbufSetStatic(&platform->systemArchitecture, "i686");
ffStrbufSetStatic(&info->architecture, "i686");
break;
default:
ffStrbufSetStatic(&platform->systemArchitecture, "i386");
ffStrbufSetStatic(&info->architecture, "i386");
break;
}
break;
case PROCESSOR_ARCHITECTURE_ARM64:
ffStrbufSetStatic(&platform->systemArchitecture, "aarch64");
ffStrbufSetStatic(&info->architecture, "aarch64");
break;
case PROCESSOR_ARCHITECTURE_ARM:
ffStrbufSetStatic(&platform->systemArchitecture, "arm");
ffStrbufSetStatic(&info->architecture, "arm");
break;
case PROCESSOR_ARCHITECTURE_PPC:
ffStrbufSetStatic(&platform->systemArchitecture, "ppc");
ffStrbufSetStatic(&info->architecture, "ppc");
break;
case PROCESSOR_ARCHITECTURE_MIPS:
ffStrbufSetStatic(&platform->systemArchitecture, "mips");
ffStrbufSetStatic(&info->architecture, "mips");
break;
case PROCESSOR_ARCHITECTURE_ALPHA:
ffStrbufSetStatic(&platform->systemArchitecture, "alpha");
ffStrbufSetStatic(&info->architecture, "alpha");
break;
case PROCESSOR_ARCHITECTURE_ALPHA64:
ffStrbufSetStatic(&platform->systemArchitecture, "alpha64");
ffStrbufSetStatic(&info->architecture, "alpha64");
break;
case PROCESSOR_ARCHITECTURE_UNKNOWN:
default:
ffStrbufSetStatic(&info->architecture, "unknown");
break;
}
platform->pageSize = sysInfo.dwPageSize;
info->pageSize = sysInfo.dwPageSize;
}
void ffPlatformInitImpl(FFPlatform* platform)
@ -272,6 +273,6 @@ void ffPlatformInitImpl(FFPlatform* platform)
getHostName(platform);
getUserShell(platform);
getSystemReleaseAndVersion(platform);
getSystemArchitectureAndPageSize(platform);
getSystemReleaseAndVersion(&platform->sysinfo);
getSystemArchitectureAndPageSize(&platform->sysinfo);
}