From 16181b7272745bb5cb74f806a653e320cc5d4975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 15 Jun 2023 10:03:12 +0800 Subject: [PATCH] Bios (FreeBSD): code refactor --- src/common/settings.c | 21 ++++++++++++++++++--- src/common/settings.h | 2 ++ src/detection/bios/bios_bsd.c | 19 +++++-------------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/common/settings.c b/src/common/settings.c index 09cf723ee..f8e88b10a 100644 --- a/src/common/settings.c +++ b/src/common/settings.c @@ -403,9 +403,24 @@ bool ffSettingsGetSQLite3String(const FFinstance* instance, const char* dbPath, #ifdef __ANDROID__ #include -void ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result) { +bool ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result) { ffStrbufEnsureFree(result, PROP_VALUE_MAX); - result->length += (uint32_t) __system_property_get(propName, result->chars + result->length); + int len = __system_property_get(propName, result->chars + result->length); + if (len <= 0) return false; + result->length += (uint32_t) len; result->chars[result->length] = '\0'; + return true; } -#endif //__ANDROID__ +#elif defined(__FreeBSD__) +#include +bool ffSettingsGetFreeBSDKenv(const char* propName, FFstrbuf* result) +{ + //https://wiki.ghostbsd.org/index.php/Kenv + ffStrbufEnsureFree(result, KENV_MVALLEN); + int len = kenv(KENV_GET, propName, result->chars + result->length, KENV_MVALLEN); + if (len <= 0) return false; + result->length += (uint32_t) len; + result->chars[result->length] = '\0'; + return true; +} +#endif diff --git a/src/common/settings.h b/src/common/settings.h index 57fbf5673..e85f51068 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -35,6 +35,8 @@ bool ffSettingsGetSQLite3String(const FFinstance* instance, const char* dbPath, #ifdef __ANDROID__ void ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result); +#elif defined(__FreeBSD__) +bool ffSettingsGetFreeBSDKenv(const char* propName, FFstrbuf* result); #endif #endif diff --git a/src/detection/bios/bios_bsd.c b/src/detection/bios/bios_bsd.c index 8c993f0a9..5699b3372 100644 --- a/src/detection/bios/bios_bsd.c +++ b/src/detection/bios/bios_bsd.c @@ -1,14 +1,6 @@ #include "bios.h" -#include - -static void kenvLookup(const char* name, FFstrbuf* result) -{ - ffStrbufEnsureFree(result, 255); - int len = kenv(KENV_GET, name, result->chars, 256); - if(len > 0) - result->length = (uint32_t) len; -} +#include "common/settings.h" void ffDetectBios(FFBiosResult* bios) { @@ -18,9 +10,8 @@ void ffDetectBios(FFBiosResult* bios) ffStrbufInit(&bios->biosVendor); ffStrbufInit(&bios->biosVersion); - //https://wiki.ghostbsd.org/index.php/Kenv - kenvLookup("smbios.bios.reldate", &bios->biosDate); - kenvLookup("smbios.system.product", &bios->biosRelease); - kenvLookup("smbios.bios.vendor", &bios->biosVendor); - kenvLookup("smbios.bios.version", &bios->biosVersion); + ffSettingsGetFreeBSDKenv("smbios.bios.reldate", &bios->biosDate); + ffSettingsGetFreeBSDKenv("smbios.bios.revision", &bios->biosRelease); + ffSettingsGetFreeBSDKenv("smbios.bios.vendor", &bios->biosVendor); + ffSettingsGetFreeBSDKenv("smbios.bios.version", &bios->biosVersion); }