From 895d151e2eb8cc975ab11f6a545d93749cca26d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 27 Oct 2022 10:46:33 +0800 Subject: [PATCH] Host: support freebsd --- CMakeLists.txt | 18 ++++++++++++++---- src/common/sysctl.c | 6 ++++-- src/common/sysctl.h | 10 ++++++---- src/detection/host/host_bsd.c | 19 +++++++++++++++++++ 4 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 src/detection/host/host_bsd.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 86a271a70..850a72a63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -331,12 +331,8 @@ endif() if(LINUX OR BSD) list(APPEND LIBFASTFETCH_SRC - src/detection/host/host_linux.c - src/detection/bios/bios_linux.c - src/detection/board/board_linux.c src/detection/os/os_linux.c src/detection/gpu/gpu_linux.c - src/detection/battery/battery_linux.c src/detection/displayserver/linux/displayserver_linux.c src/detection/displayserver/linux/wayland.c src/detection/displayserver/linux/xcb.c @@ -351,6 +347,15 @@ if(LINUX OR BSD) ) endif() +if(LINUX) + list(APPEND LIBFASTFETCH_SRC + src/detection/host/host_linux.c + src/detection/bios/bios_linux.c + src/detection/board/board_linux.c + src/detection/battery/battery_linux.c + ) +endif() + if(WIN32) list(APPEND LIBFASTFETCH_SRC src/common/processing_windows.c @@ -421,6 +426,11 @@ if(BSD) src/detection/cpuUsage/cpuUsage_bsd.c src/detection/memory/memory_bsd.c src/detection/swap/swap_bsd.c + src/detection/host/host_bsd.c + + src/detection/battery/battery_nosupport.c + src/detection/bios/bios_nosupport.c + src/detection/board/board_nosupport.c ) endif() diff --git a/src/common/sysctl.c b/src/common/sysctl.c index 30e92383a..4f0f3b65c 100644 --- a/src/common/sysctl.c +++ b/src/common/sysctl.c @@ -2,11 +2,11 @@ #include -void ffSysctlGetString(const char* propName, FFstrbuf* result) +const char* ffSysctlGetString(const char* propName, FFstrbuf* result) { size_t neededLength; if(sysctlbyname(propName, NULL, &neededLength, NULL, 0) != 0 || neededLength == 1) //neededLength is 1 for empty strings, because of the null terminator - return; + return "sysctlbyname() failed"; ffStrbufEnsureFree(result, (uint32_t) neededLength - 1); @@ -14,6 +14,8 @@ void ffSysctlGetString(const char* propName, FFstrbuf* result) result->length += (uint32_t) neededLength - 1; result->chars[result->length] = '\0'; + + return NULL; } int ffSysctlGetInt(const char* propName, int defaultValue) diff --git a/src/common/sysctl.h b/src/common/sysctl.h index 91e4ad8b6..562e625d5 100644 --- a/src/common/sysctl.h +++ b/src/common/sysctl.h @@ -4,12 +4,14 @@ #define FF_INCLUDED_common_sysctl #include "fastfetch.h" +#include "util/FFcheckmacros.h" + #include #include -void ffSysctlGetString(const char* propName, FFstrbuf* result); -int ffSysctlGetInt(const char* propName, int defaultValue); -int64_t ffSysctlGetInt64(const char* propName, int64_t defaultValue); -void* ffSysctlGetData(int* request, u_int requestLength, size_t* resultLength); +const char* ffSysctlGetString(const char* propName, FFstrbuf* result); +FF_C_NODISCARD int ffSysctlGetInt(const char* propName, int defaultValue); +FF_C_NODISCARD int64_t ffSysctlGetInt64(const char* propName, int64_t defaultValue); +FF_C_NODISCARD void* ffSysctlGetData(int* request, u_int requestLength, size_t* resultLength); #endif diff --git a/src/detection/host/host_bsd.c b/src/detection/host/host_bsd.c new file mode 100644 index 000000000..13a43acda --- /dev/null +++ b/src/detection/host/host_bsd.c @@ -0,0 +1,19 @@ +#include "host.h" +#include "common/sysctl.h" + +void ffDetectHostImpl(FFHostResult* host) +{ + ffStrbufInit(&host->error); + + ffStrbufInit(&host->productName); + ffStrbufInit(&host->productFamily); + ffStrbufInit(&host->productVersion); + ffStrbufInit(&host->productSku); + + ffStrbufInit(&host->sysVendor); + ffStrbufInit(&host->chassisType); + ffStrbufInit(&host->chassisVendor); + ffStrbufInit(&host->chassisVersion); + + ffStrbufAppendS(&host->error, ffSysctlGetString("hw.fdt.model", &host->productName)); +}