diff --git a/CMakeLists.txt b/CMakeLists.txt index bea9db531..3c735c21d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -254,7 +254,6 @@ set(LIBFASTFETCH_SRC src/detection/displayserver/displayserver.c src/detection/font/font.c src/detection/gpu/gpu.c - src/detection/host/host.c src/detection/locale/locale.c src/detection/media/media.c src/detection/opencl/opencl.c diff --git a/src/detection/host/host.c b/src/detection/host/host.c deleted file mode 100644 index ea8274dbe..000000000 --- a/src/detection/host/host.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "host.h" -#include "detection/internal.h" - -void ffDetectHostImpl(FFHostResult* host); - -const FFHostResult* ffDetectHost() -{ - FF_DETECTION_INTERNAL_GUARD(FFHostResult, - ffDetectHostImpl(&result) - ); -} diff --git a/src/detection/host/host.h b/src/detection/host/host.h index c8b47b6b2..a0fd66511 100644 --- a/src/detection/host/host.h +++ b/src/detection/host/host.h @@ -12,9 +12,8 @@ typedef struct FFHostResult FFstrbuf productVersion; FFstrbuf productSku; FFstrbuf sysVendor; - FFstrbuf error; } FFHostResult; -const FFHostResult* ffDetectHost(); +const char* ffDetectHost(FFHostResult* result); #endif diff --git a/src/detection/host/host_android.c b/src/detection/host/host_android.c index 240a65b9d..384faf736 100644 --- a/src/detection/host/host_android.c +++ b/src/detection/host/host_android.c @@ -2,10 +2,8 @@ #include "common/settings.h" #include -void ffDetectHostImpl(FFHostResult* host) +const char* ffDetectHost(FFHostResult* host) { - ffStrbufInit(&host->error); - //Family ffStrbufInit(&host->productFamily); @@ -16,7 +14,8 @@ void ffDetectHostImpl(FFHostResult* host) ffStrbufInit(&host->productName); ffSettingsGetAndroidProperty("ro.product.brand", &host->productName); - if(host->productName.length > 0){ + if(host->productName.length > 0) + { host->productName.chars[0] = (char) toupper(host->productName.chars[0]); ffStrbufAppendC(&host->productName, ' '); } @@ -34,4 +33,6 @@ void ffDetectHostImpl(FFHostResult* host) ffStrbufInit(&host->productVersion); ffStrbufInit(&host->productSku); + + return NULL; } diff --git a/src/detection/host/host_apple.c b/src/detection/host/host_apple.c index 4f739276b..8755795d4 100644 --- a/src/detection/host/host_apple.c +++ b/src/detection/host/host_apple.c @@ -155,17 +155,16 @@ static const char* getProductName(const FFstrbuf* hwModel) return hwModel->chars; } -void ffDetectHostImpl(FFHostResult* host) +const char* ffDetectHost(FFHostResult* host) { - ffStrbufInit(&host->error); - ffStrbufInit(&host->productName); ffStrbufInit(&host->productFamily); ffStrbufInit(&host->productVersion); ffStrbufInit(&host->productSku); ffStrbufInitS(&host->sysVendor, "Apple"); - ffStrbufAppendS(&host->error, ffSysctlGetString("hw.model", &host->productFamily)); - if(host->error.length == 0) - ffStrbufAppendS(&host->productName, getProductName(&host->productFamily)); + const char* error = ffSysctlGetString("hw.model", &host->productFamily); + if (error) return error; + ffStrbufAppendS(&host->productName, getProductName(&host->productFamily)); + return NULL; } diff --git a/src/detection/host/host_bsd.c b/src/detection/host/host_bsd.c index 8be64b6c3..d4b99e952 100644 --- a/src/detection/host/host_bsd.c +++ b/src/detection/host/host_bsd.c @@ -1,15 +1,13 @@ #include "host.h" #include "common/sysctl.h" -void ffDetectHostImpl(FFHostResult* host) +const char* ffDetectHost(FFHostResult* host) { - ffStrbufInit(&host->error); - ffStrbufInit(&host->productName); ffStrbufInit(&host->productFamily); ffStrbufInit(&host->productVersion); ffStrbufInit(&host->productSku); ffStrbufInit(&host->sysVendor); - ffStrbufAppendS(&host->error, ffSysctlGetString("hw.fdt.model", &host->productName)); + return ffSysctlGetString("hw.fdt.model", &host->productName); } diff --git a/src/detection/host/host_linux.c b/src/detection/host/host_linux.c index 766b4f47a..57e8f6caf 100644 --- a/src/detection/host/host_linux.c +++ b/src/detection/host/host_linux.c @@ -59,10 +59,8 @@ static void getHostProductName(FFstrbuf* name) ffStrbufClear(name); } -void ffDetectHostImpl(FFHostResult* host) +const char* ffDetectHost(FFHostResult* host) { - ffStrbufInit(&host->error); - ffStrbufInit(&host->productFamily); getHostValue("/sys/devices/virtual/dmi/id/product_family", "/sys/class/dmi/id/product_family", &host->productFamily); @@ -107,4 +105,6 @@ void ffDetectHostImpl(FFHostResult* host) } } } + + return NULL; } diff --git a/src/detection/host/host_windows.c b/src/detection/host/host_windows.c index 75afd0563..1a940e1ac 100644 --- a/src/detection/host/host_windows.c +++ b/src/detection/host/host_windows.c @@ -1,10 +1,8 @@ #include "host.h" #include "util/windows/registry.h" -void ffDetectHostImpl(FFHostResult* host) +const char* ffDetectHost(FFHostResult* host) { - ffStrbufInit(&host->error); - ffStrbufInit(&host->productName); ffStrbufInit(&host->productFamily); ffStrbufInit(&host->productVersion); @@ -13,12 +11,14 @@ void ffDetectHostImpl(FFHostResult* host) FF_HKEY_AUTO_DESTROY hKey = NULL; - if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\BIOS", &hKey, &host->error)) - return; + if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\BIOS", &hKey, NULL)) + return "ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L\"HARDWARE\\DESCRIPTION\\System\\BIOS\", &hKey, NULL) failed"; ffRegReadStrbuf(hKey, L"SystemProductName", &host->productName, NULL); ffRegReadStrbuf(hKey, L"SystemFamily", &host->productFamily, NULL); ffRegReadStrbuf(hKey, L"SystemVersion", &host->productVersion, NULL); ffRegReadStrbuf(hKey, L"SystemSKU", &host->productSku, NULL); ffRegReadStrbuf(hKey, L"SystemManufacturer", &host->sysVendor, NULL); + + return NULL; } diff --git a/src/modules/host/host.c b/src/modules/host/host.c index b63a1bb87..b6c7f5b73 100644 --- a/src/modules/host/host.c +++ b/src/modules/host/host.c @@ -7,18 +7,19 @@ void ffPrintHost(FFinstance* instance, FFHostOptions* options) { - const FFHostResult* host = ffDetectHost(); + FFHostResult host; + const char* error = ffDetectHost(&host); - if(host->error.length > 0) + if(error) { - ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &options->moduleArgs, "%*s", host->error.length, host->error.chars); - return; + ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &options->moduleArgs, "%s", error); + goto exit; } - if(host->productFamily.length == 0 && host->productName.length == 0) + if(host.productFamily.length == 0 && host.productName.length == 0) { ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &options->moduleArgs, "neither product_family nor product_name is set by O.E.M."); - return; + goto exit; } if(options->moduleArgs.outputFormat.length == 0) @@ -27,14 +28,14 @@ void ffPrintHost(FFinstance* instance, FFHostOptions* options) FF_STRBUF_AUTO_DESTROY output = ffStrbufCreate(); - if(host->productName.length > 0) - ffStrbufAppend(&output, &host->productName); + if(host.productName.length > 0) + ffStrbufAppend(&output, &host.productName); else - ffStrbufAppend(&output, &host->productFamily); + ffStrbufAppend(&output, &host.productFamily); - if(host->productVersion.length > 0 && !ffStrbufIgnCaseEqualS(&host->productVersion, "none")) + if(host.productVersion.length > 0 && !ffStrbufIgnCaseEqualS(&host.productVersion, "none")) { - ffStrbufAppendF(&output, " (%s)", host->productVersion.chars); + ffStrbufAppendF(&output, " (%s)", host.productVersion.chars); } ffStrbufPutTo(&output, stdout); @@ -42,13 +43,20 @@ void ffPrintHost(FFinstance* instance, FFHostOptions* options) else { ffPrintFormat(instance, FF_HOST_MODULE_NAME, 0, &options->moduleArgs, FF_HOST_NUM_FORMAT_ARGS, (FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &host->productFamily}, - {FF_FORMAT_ARG_TYPE_STRBUF, &host->productName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &host->productVersion}, - {FF_FORMAT_ARG_TYPE_STRBUF, &host->productSku}, - {FF_FORMAT_ARG_TYPE_STRBUF, &host->sysVendor} + {FF_FORMAT_ARG_TYPE_STRBUF, &host.productFamily}, + {FF_FORMAT_ARG_TYPE_STRBUF, &host.productName}, + {FF_FORMAT_ARG_TYPE_STRBUF, &host.productVersion}, + {FF_FORMAT_ARG_TYPE_STRBUF, &host.productSku}, + {FF_FORMAT_ARG_TYPE_STRBUF, &host.sysVendor} }); } + +exit: + ffStrbufDestroy(&host.productFamily); + ffStrbufDestroy(&host.productName); + ffStrbufDestroy(&host.productVersion); + ffStrbufDestroy(&host.productSku); + ffStrbufDestroy(&host.sysVendor); } void ffInitHostOptions(FFHostOptions* options)