Bios (FreeBSD): code refactor

This commit is contained in:
李通洲
2023-06-15 10:03:12 +08:00
parent a18073f5de
commit 16181b7272
3 changed files with 25 additions and 17 deletions
+18 -3
View File
@@ -403,9 +403,24 @@ bool ffSettingsGetSQLite3String(const FFinstance* instance, const char* dbPath,
#ifdef __ANDROID__
#include <sys/system_properties.h>
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 <kenv.h>
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
+2
View File
@@ -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
+5 -14
View File
@@ -1,14 +1,6 @@
#include "bios.h"
#include <kenv.h>
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);
}