From d35490aeef6c8c43da2b76969e0aed59545f1fb0 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 16 Jun 2024 01:02:48 +0800 Subject: [PATCH] Fastfetch: make it compile on SunOS --- CMakeLists.txt | 80 +++++++++++++++++++ src/common/io/io_unix.c | 22 ++++- src/detection/bios/bios_nosupport.c | 6 ++ src/detection/camera/camera_nosupport.c | 6 ++ src/detection/cpu/cpu_nosupport.c | 6 ++ src/detection/cpucache/cpucache_nosupport.c | 1 - src/detection/cpuusage/cpuusage_nosupport.c | 7 ++ src/detection/disk/disk_nosupport.c | 6 ++ src/detection/diskio/diskio_nosupport.c | 6 ++ src/detection/displayserver/linux/wmde.c | 2 +- src/detection/host/host_nosupport.c | 6 ++ src/detection/libc/libc_nosupport.c | 8 ++ src/detection/localip/localip_linux.c | 2 + src/detection/memory/memory_nosupport.c | 6 ++ src/detection/netio/netio_nosupport.c | 6 ++ src/detection/os/os_sunos.c | 20 +++++ src/detection/packages/packages_nosupport.c | 5 ++ .../physicaldisk/physicaldisk_nosupport.c | 6 ++ src/detection/processes/processes_linux.c | 6 +- src/detection/swap/swap_nosupport.c | 6 ++ .../terminalsize/terminalsize_linux.c | 1 + src/detection/uptime/uptime_sunos.c | 21 +++++ src/detection/wifi/wifi_nosupport.c | 6 ++ src/options/general.c | 2 +- src/options/general.h | 2 +- src/util/platform/FFPlatform_unix.c | 4 +- 26 files changed, 241 insertions(+), 8 deletions(-) create mode 100644 src/detection/bios/bios_nosupport.c create mode 100644 src/detection/camera/camera_nosupport.c create mode 100644 src/detection/cpu/cpu_nosupport.c create mode 100644 src/detection/cpuusage/cpuusage_nosupport.c create mode 100644 src/detection/disk/disk_nosupport.c create mode 100644 src/detection/diskio/diskio_nosupport.c create mode 100644 src/detection/host/host_nosupport.c create mode 100644 src/detection/libc/libc_nosupport.c create mode 100644 src/detection/memory/memory_nosupport.c create mode 100644 src/detection/netio/netio_nosupport.c create mode 100644 src/detection/os/os_sunos.c create mode 100644 src/detection/packages/packages_nosupport.c create mode 100644 src/detection/physicaldisk/physicaldisk_nosupport.c create mode 100644 src/detection/swap/swap_nosupport.c create mode 100644 src/detection/uptime/uptime_sunos.c create mode 100644 src/detection/wifi/wifi_nosupport.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 7dbafe741..aeaf53fa8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,8 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") set(LINUX TRUE CACHE BOOL "..." FORCE) # LINUX means GNU/Linux, not just the kernel elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") set(BSD TRUE CACHE BOOL "..." FORCE) +elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") + set(SunOS TRUE CACHE BOOL "..." FORCE) elseif(NOT APPLE AND NOT WIN32) message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}") endif() @@ -733,6 +735,77 @@ elseif(WIN32) src/util/windows/wmi.cpp src/util/platform/FFPlatform_windows.c ) +elseif(SunOS) + list(APPEND LIBFASTFETCH_SRC + src/common/dbus.c + src/common/io/io_unix.c + src/common/netif/netif_linux.c + src/common/networking_linux.c + src/common/processing_linux.c + src/detection/battery/battery_nosupport.c + src/detection/bios/bios_nosupport.c + src/detection/board/board_nosupport.c + src/detection/bootmgr/bootmgr_nosupport.c + src/detection/brightness/brightness_nosupport.c + src/detection/chassis/chassis_nosupport.c + src/detection/cpu/cpu_nosupport.c + src/detection/cpucache/cpucache_nosupport.c + src/detection/cpuusage/cpuusage_nosupport.c + src/detection/cursor/cursor_linux.c + src/detection/bluetooth/bluetooth_nosupport.c + src/detection/disk/disk_nosupport.c + src/detection/dns/dns_linux.c + src/detection/physicaldisk/physicaldisk_nosupport.c + src/detection/physicalmemory/physicalmemory_nosupport.c + src/detection/diskio/diskio_nosupport.c + src/detection/displayserver/linux/displayserver_linux.c + src/detection/displayserver/linux/drm.c + src/detection/displayserver/linux/wayland/wayland.c + src/detection/displayserver/linux/wayland/global-output.c + src/detection/displayserver/linux/wayland/zwlr-output.c + src/detection/displayserver/linux/wayland/wlr-output-management-unstable-v1-protocol.c + src/detection/displayserver/linux/wmde.c + src/detection/displayserver/linux/xcb.c + src/detection/displayserver/linux/xlib.c + src/detection/font/font_linux.c + src/detection/gpu/gpu_nosupport.c + src/detection/gpu/gpu_pci.c + src/detection/gtk_qt/gtk.c + src/detection/host/host_nosupport.c + src/detection/icons/icons_nosupport.c + src/detection/initsystem/initsystem_nosupport.c + src/detection/libc/libc_nosupport.c + src/detection/lm/lm_nosupport.c + src/detection/loadavg/loadavg_nosupport.c + src/detection/locale/locale_linux.c + src/detection/localip/localip_linux.c + src/detection/gamepad/gamepad_nosupport.c + src/detection/media/media_linux.c + src/detection/memory/memory_nosupport.c + src/detection/monitor/monitor_nosupport.c + src/detection/netio/netio_nosupport.c + src/detection/opengl/opengl_linux.c + src/detection/os/os_sunos.c + src/detection/packages/packages_nosupport.c + src/detection/poweradapter/poweradapter_nosupport.c + src/detection/processes/processes_linux.c + src/detection/gtk_qt/qt.c + src/detection/sound/sound_nosupport.c + src/detection/swap/swap_nosupport.c + src/detection/terminalfont/terminalfont_linux.c + src/detection/terminalshell/terminalshell_linux.c + src/detection/terminalsize/terminalsize_linux.c + src/detection/theme/theme_linux.c + src/detection/uptime/uptime_sunos.c + src/detection/users/users_linux.c + src/detection/wallpaper/wallpaper_linux.c + src/detection/wifi/wifi_nosupport.c + src/detection/wm/wm_nosupport.c + src/detection/de/de_linux.c + src/detection/wmtheme/wmtheme_linux.c + src/detection/camera/camera_nosupport.c + src/util/platform/FFPlatform_unix.c + ) endif() if(ENABLE_DIRECTX_HEADERS) @@ -820,6 +893,8 @@ if(WIN32) target_compile_definitions(libfastfetch PUBLIC WIN32_LEAN_AND_MEAN=1) elseif(APPLE) target_compile_definitions(libfastfetch PUBLIC _DARWIN_C_SOURCE) +elseif(SunOS) + target_compile_definitions(libfastfetch PUBLIC __EXTENSIONS__ _POSIX_C_SOURCE=1) endif() if(HAVE_STATX) @@ -1049,6 +1124,11 @@ elseif(BSD) PRIVATE "usbhid" PRIVATE "geom" ) +elseif(SunOS) + target_link_libraries(libfastfetch + PRIVATE "m" + PRIVATE "socket" + ) elseif(ANDROID) CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC) if(HAVE_LIBANDROID_WORDEXP_STATIC) diff --git a/src/common/io/io_unix.c b/src/common/io/io_unix.c index d204de1ea..501e23015 100644 --- a/src/common/io/io_unix.c +++ b/src/common/io/io_unix.c @@ -204,7 +204,11 @@ bool ffSuppressIO(bool suppress) void listFilesRecursively(uint32_t baseLength, FFstrbuf* folder, uint8_t indentation, const char* folderName, bool pretty) { - DIR* dir = opendir(folder->chars); + FF_AUTO_CLOSE_FD int dfd = open(folder->chars, O_RDONLY); + if (dfd < 0) + return; + + DIR* dir = fdopendir(dfd); if(dir == NULL) return; @@ -221,7 +225,21 @@ void listFilesRecursively(uint32_t baseLength, FFstrbuf* folder, uint8_t indenta while((entry = readdir(dir)) != NULL) { - if(entry->d_type == DT_DIR) + bool isDir = false; +#ifdef _DIRENT_HAVE_D_TYPE + if(entry->d_type != DT_UNKNOWN && entry->d_type != DT_LNK) + isDir = entry->d_type == DT_DIR; + else +#else + { + struct stat stbuf; + if (fstatat(dfd, entry->d_name, &stbuf, 0) < 0) + isDir = false; + else + isDir = S_ISDIR(stbuf.st_mode); + } +#endif + if (isDir) { if(ffStrEquals(entry->d_name, ".") || ffStrEquals(entry->d_name, "..")) continue; diff --git a/src/detection/bios/bios_nosupport.c b/src/detection/bios/bios_nosupport.c new file mode 100644 index 000000000..76abc7a12 --- /dev/null +++ b/src/detection/bios/bios_nosupport.c @@ -0,0 +1,6 @@ +#include "bios.h" + +const char* ffDetectBios(FFBiosResult* bios) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/camera/camera_nosupport.c b/src/detection/camera/camera_nosupport.c new file mode 100644 index 000000000..383e4cec1 --- /dev/null +++ b/src/detection/camera/camera_nosupport.c @@ -0,0 +1,6 @@ +#include "camera.h" + +const char* ffDetectCamera(FF_MAYBE_UNUSED FFlist* result) +{ + return "Not support on this platform"; +} diff --git a/src/detection/cpu/cpu_nosupport.c b/src/detection/cpu/cpu_nosupport.c new file mode 100644 index 000000000..2a06915d2 --- /dev/null +++ b/src/detection/cpu/cpu_nosupport.c @@ -0,0 +1,6 @@ +#include "cpu.h" + +const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/cpucache/cpucache_nosupport.c b/src/detection/cpucache/cpucache_nosupport.c index 5d5291209..b405b9079 100644 --- a/src/detection/cpucache/cpucache_nosupport.c +++ b/src/detection/cpucache/cpucache_nosupport.c @@ -1,5 +1,4 @@ #include "cpucache.h" -#include "common/sysctl.h" const char* ffDetectCPUCache(FF_MAYBE_UNUSED FFCPUCacheResult* result) { diff --git a/src/detection/cpuusage/cpuusage_nosupport.c b/src/detection/cpuusage/cpuusage_nosupport.c new file mode 100644 index 000000000..72770e3be --- /dev/null +++ b/src/detection/cpuusage/cpuusage_nosupport.c @@ -0,0 +1,7 @@ +#include "fastfetch.h" +#include "detection/cpuusage/cpuusage.h" + +const char* ffGetCpuUsageInfo(FFlist* cpuTimes) +{ + return "Not support on this platform"; +} diff --git a/src/detection/disk/disk_nosupport.c b/src/detection/disk/disk_nosupport.c new file mode 100644 index 000000000..cd224572a --- /dev/null +++ b/src/detection/disk/disk_nosupport.c @@ -0,0 +1,6 @@ +#include "disk.h" + +const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/diskio/diskio_nosupport.c b/src/detection/diskio/diskio_nosupport.c new file mode 100644 index 000000000..2e165c0c5 --- /dev/null +++ b/src/detection/diskio/diskio_nosupport.c @@ -0,0 +1,6 @@ +#include "diskio.h" + +const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/displayserver/linux/wmde.c b/src/detection/displayserver/linux/wmde.c index 10ea048d1..3bf4c3d11 100644 --- a/src/detection/displayserver/linux/wmde.c +++ b/src/detection/displayserver/linux/wmde.c @@ -302,7 +302,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result) if(result->dePrettyName.length > 0 && result->wmPrettyName.length > 0) break; } -#else +#elif !defined(__sun) FF_AUTO_CLOSE_DIR DIR* procdir = opendir("/proc"); if(procdir == NULL) return "opendir(\"/proc\") failed"; diff --git a/src/detection/host/host_nosupport.c b/src/detection/host/host_nosupport.c new file mode 100644 index 000000000..6f3934823 --- /dev/null +++ b/src/detection/host/host_nosupport.c @@ -0,0 +1,6 @@ +#include "host.h" + +const char* ffDetectHost(FFHostResult* host) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/libc/libc_nosupport.c b/src/detection/libc/libc_nosupport.c new file mode 100644 index 000000000..be1316cce --- /dev/null +++ b/src/detection/libc/libc_nosupport.c @@ -0,0 +1,8 @@ +#include "libc.h" + +const char* ffDetectLibc(FFLibcResult* result) +{ + result->name = "Unknown"; + result->version = NULL; + return NULL; +} diff --git a/src/detection/localip/localip_linux.c b/src/detection/localip/localip_linux.c index 0a8e3a05d..3802bb10e 100644 --- a/src/detection/localip/localip_linux.c +++ b/src/detection/localip/localip_linux.c @@ -162,6 +162,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) if (ifAddrStruct) freeifaddrs(ifAddrStruct); +#ifdef SIOCGIFMTU FF_AUTO_CLOSE_FD int sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd > 0) { @@ -173,6 +174,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) iface->mtu = ifr.ifr_mtu; } } +#endif return NULL; } diff --git a/src/detection/memory/memory_nosupport.c b/src/detection/memory/memory_nosupport.c new file mode 100644 index 000000000..76cd7f828 --- /dev/null +++ b/src/detection/memory/memory_nosupport.c @@ -0,0 +1,6 @@ +#include "memory.h" + +const char* ffDetectMemory(FFMemoryResult* ram) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/netio/netio_nosupport.c b/src/detection/netio/netio_nosupport.c new file mode 100644 index 000000000..254f22860 --- /dev/null +++ b/src/detection/netio/netio_nosupport.c @@ -0,0 +1,6 @@ +#include "netio.h" + +const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/os/os_sunos.c b/src/detection/os/os_sunos.c new file mode 100644 index 000000000..3f6d2a6df --- /dev/null +++ b/src/detection/os/os_sunos.c @@ -0,0 +1,20 @@ +#include "os.h" +#include "common/io/io.h" + +void ffDetectOSImpl(FFOSResult* os) +{ + if (!ffReadFileBuffer("/etc/release", &os->prettyName)) + return; + + ffStrbufSubstrBeforeFirstC(&os->prettyName, '\n'); + ffStrbufSubstrBeforeLastC(&os->prettyName, '('); + ffStrbufTrim(&os->prettyName, ' '); + + // OpenIndiana Hipster 2024.04 + uint32_t idx = ffStrbufFirstIndexC(&os->prettyName, ' '); + ffStrbufSetNS(&os->name, idx, os->prettyName.chars); + uint32_t idx2 = ffStrbufNextIndexC(&os->prettyName, idx + 1, ' '); + ffStrbufSetNS(&os->codename, idx2 - idx - 1, os->prettyName.chars + idx + 1); + ffStrbufSetNS(&os->version, idx2 - idx - 1, os->prettyName.chars + idx2 + 1); + ffStrbufSetStatic(&os->idLike, "sunos"); +} diff --git a/src/detection/packages/packages_nosupport.c b/src/detection/packages/packages_nosupport.c new file mode 100644 index 000000000..87f65a8eb --- /dev/null +++ b/src/detection/packages/packages_nosupport.c @@ -0,0 +1,5 @@ +#include "packages.h" + +void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options) +{ +} diff --git a/src/detection/physicaldisk/physicaldisk_nosupport.c b/src/detection/physicaldisk/physicaldisk_nosupport.c new file mode 100644 index 000000000..1ed823d9c --- /dev/null +++ b/src/detection/physicaldisk/physicaldisk_nosupport.c @@ -0,0 +1,6 @@ +#include "physicaldisk.h" + +const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/processes/processes_linux.c b/src/detection/processes/processes_linux.c index 25e3a84af..58fea6416 100644 --- a/src/detection/processes/processes_linux.c +++ b/src/detection/processes/processes_linux.c @@ -14,7 +14,11 @@ const char* ffDetectProcesses(uint32_t* result) struct dirent* entry; while ((entry = readdir(dir)) != NULL) { - if (entry->d_type == DT_DIR && ffCharIsDigit(entry->d_name[0])) + if ( + #ifdef _DIRENT_HAVE_D_TYPE + entry->d_type == DT_DIR && + #endif + ffCharIsDigit(entry->d_name[0])) ++num; } diff --git a/src/detection/swap/swap_nosupport.c b/src/detection/swap/swap_nosupport.c new file mode 100644 index 000000000..98a11195f --- /dev/null +++ b/src/detection/swap/swap_nosupport.c @@ -0,0 +1,6 @@ +#include "swap.h" + +const char* ffDetectSwap(FFSwapResult* swap) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/terminalsize/terminalsize_linux.c b/src/detection/terminalsize/terminalsize_linux.c index b15939661..bc224eb93 100644 --- a/src/detection/terminalsize/terminalsize_linux.c +++ b/src/detection/terminalsize/terminalsize_linux.c @@ -1,6 +1,7 @@ #include "terminalsize.h" #include "common/io/io.h" +#include #include #include diff --git a/src/detection/uptime/uptime_sunos.c b/src/detection/uptime/uptime_sunos.c new file mode 100644 index 000000000..e50348365 --- /dev/null +++ b/src/detection/uptime/uptime_sunos.c @@ -0,0 +1,21 @@ +#include "uptime.h" +#include "common/time.h" +#include + +const char* ffDetectUptime(FFUptimeResult* result) +{ + struct utmpx* ut; + + setutxent(); + while (NULL != (ut = getutxent())) + { + if (ut->ut_type == BOOT_TIME) + { + result->bootTime = (uint64_t) ut->ut_tv.tv_sec * 1000 + (uint64_t) ut->ut_tv.tv_usec / 10000000; + result->uptime = ffTimeGetNow() - result->bootTime; + break; + } + } + endutxent(); + return NULL; +} diff --git a/src/detection/wifi/wifi_nosupport.c b/src/detection/wifi/wifi_nosupport.c new file mode 100644 index 000000000..ae1d62e09 --- /dev/null +++ b/src/detection/wifi/wifi_nosupport.c @@ -0,0 +1,6 @@ +#include "wifi.h" + +const char* ffDetectWifi(FFlist* result) +{ + return "Not support on this platform"; +} diff --git a/src/options/general.c b/src/options/general.c index f27dce3e5..3b5247aa4 100644 --- a/src/options/general.c +++ b/src/options/general.c @@ -22,7 +22,7 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va else if (ffStrEqualsIgnCase(key, "processingTimeout")) options->processingTimeout = (int32_t) yyjson_get_int(val); - #if defined(__linux__) || defined(__FreeBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) else if (ffStrEqualsIgnCase(key, "escapeBedrock")) options->escapeBedrock = yyjson_get_bool(val); else if (ffStrEqualsIgnCase(key, "playerName")) diff --git a/src/options/general.h b/src/options/general.h index 0ab8ee5a7..b388f3f43 100644 --- a/src/options/general.h +++ b/src/options/general.h @@ -15,7 +15,7 @@ typedef struct FFOptionsGeneral int32_t processingTimeout; // Module options that cannot be put in module option structure - #if defined(__linux__) || defined(__FreeBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) FFstrbuf playerName; bool escapeBedrock; FFDsForceDrmType dsForceDrm; diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index b57bb499d..d4d39babb 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -34,6 +34,8 @@ static void getExePath(FFPlatform* platform) exePathLen = 0; else exePathLen--; // remove terminating NUL + #else + int exePathLen = 0; #endif if (exePathLen > 0) { @@ -181,7 +183,7 @@ void ffPlatformInitImpl(FFPlatform* platform) struct passwd* pwd = getpwuid(getuid()); struct utsname uts; - if(uname(&uts) != 0) + if(uname(&uts) < 0) memset(&uts, 0, sizeof(uts)); getExePath(platform);