diff --git a/CMakeLists.txt b/CMakeLists.txt index d6a49cdc7e..97340f30b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,8 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") set(SunOS TRUE CACHE BOOL "..." FORCE) elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Haiku") set(Haiku TRUE CACHE BOOL "..." FORCE) +elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "GNU") + set(GNU TRUE CACHE BOOL "..." FORCE) elseif(NOT APPLE AND NOT WIN32) message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}") endif() @@ -56,30 +58,30 @@ include(CheckIncludeFile) include(CMakeDependentOption) -cmake_dependent_option(ENABLE_VULKAN "Enable vulkan" ON "LINUX OR APPLE OR FreeBSD OR OpenBSD OR NetBSD OR WIN32 OR ANDROID OR SunOS OR Haiku" OFF) -cmake_dependent_option(ENABLE_WAYLAND "Enable wayland-client" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD" OFF) -cmake_dependent_option(ENABLE_XCB_RANDR "Enable xcb-randr" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_XRANDR "Enable xrandr" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_DRM "Enable libdrm" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_DRM_AMDGPU "Enable libdrm_amdgpu" ON "LINUX OR FreeBSD" OFF) -cmake_dependent_option(ENABLE_GIO "Enable gio-2.0" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_DCONF "Enable dconf" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_DBUS "Enable dbus-1" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR Haiku" OFF) -cmake_dependent_option(ENABLE_XFCONF "Enable libxfconf-0" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_SQLITE3 "Enable sqlite3" ON "LINUX OR FreeBSD OR APPLE OR OpenBSD OR NetBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_RPM "Enable rpm" ON "LINUX" OFF) -cmake_dependent_option(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR APPLE OR WIN32 OR SunOS OR Haiku" OFF) -cmake_dependent_option(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR APPLE OR SunOS" OFF) +cmake_dependent_option(ENABLE_VULKAN "Enable vulkan" ON "LINUX OR APPLE OR FreeBSD OR OpenBSD OR NetBSD OR WIN32 OR ANDROID OR SunOS OR Haiku OR GNU" OFF) +cmake_dependent_option(ENABLE_WAYLAND "Enable wayland-client" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR GNU" OFF) +cmake_dependent_option(ENABLE_XCB_RANDR "Enable xcb-randr" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF) +cmake_dependent_option(ENABLE_XRANDR "Enable xrandr" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF) +cmake_dependent_option(ENABLE_DRM "Enable libdrm" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF) +cmake_dependent_option(ENABLE_DRM_AMDGPU "Enable libdrm_amdgpu" ON "LINUX OR FreeBSD OR GNU" OFF) +cmake_dependent_option(ENABLE_GIO "Enable gio-2.0" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF) +cmake_dependent_option(ENABLE_DCONF "Enable dconf" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF) +cmake_dependent_option(ENABLE_DBUS "Enable dbus-1" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR Haiku OR GNU" OFF) +cmake_dependent_option(ENABLE_XFCONF "Enable libxfconf-0" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF) +cmake_dependent_option(ENABLE_SQLITE3 "Enable sqlite3" ON "LINUX OR FreeBSD OR APPLE OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF) +cmake_dependent_option(ENABLE_RPM "Enable rpm" ON "LINUX OR GNU" OFF) +cmake_dependent_option(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR APPLE OR WIN32 OR SunOS OR Haiku OR GNU" OFF) +cmake_dependent_option(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR APPLE OR SunOS OR GNU" OFF) cmake_dependent_option(ENABLE_CHAFA "Enable chafa" ON "ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7" OFF) cmake_dependent_option(ENABLE_ZLIB "Enable zlib" ON "ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7" OFF) -cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR WIN32 OR SunOS OR Haiku" OFF) -cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS" OFF) -cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR WIN32 OR ANDROID OR SunOS OR Haiku" OFF) +cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR WIN32 OR SunOS OR Haiku OR GNU" OFF) +cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF) +cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR WIN32 OR ANDROID OR SunOS OR Haiku OR GNU" OFF) cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF) -cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX" OFF) +cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR GNU" OFF) cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF) cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" ON "LINUX" OFF) -cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID OR DragonFly OR Haiku" OFF) +cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID OR DragonFly OR Haiku OR GNU" OFF) cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF) cmake_dependent_option(ENABLE_LIBZFS "Enable libzfs" ON "LINUX OR FreeBSD OR SunOS" OFF) cmake_dependent_option(ENABLE_PCIACCESS "Enable libpciaccess" ON "NetBSD OR OpenBSD" OFF) @@ -1192,6 +1194,84 @@ elseif(Haiku) src/util/binary_linux.c src/util/haiku/version.cpp ) +elseif(GNU) + list(APPEND LIBFASTFETCH_SRC + src/common/dbus.c + src/common/io/io_unix.c + src/common/netif/netif_gnu.c + src/common/networking/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/btrfs/btrfs_nosupport.c + src/detection/chassis/chassis_nosupport.c + src/detection/cpu/cpu_linux.c + src/detection/cpucache/cpucache_nosupport.c + src/detection/cpuusage/cpuusage_linux.c + src/detection/cursor/cursor_linux.c + src/detection/bluetooth/bluetooth_linux.c + src/detection/bluetoothradio/bluetoothradio_linux.c + src/detection/disk/disk_linux.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_linux.c + src/detection/initsystem/initsystem_linux.c + src/detection/keyboard/keyboard_nosupport.c + src/detection/libc/libc_linux.c + src/detection/lm/lm_linux.c + src/detection/loadavg/loadavg_linux.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_linux.c + src/detection/mouse/mouse_nosupport.c + src/detection/netio/netio_nosupport.c + src/detection/opengl/opengl_linux.c + src/detection/os/os_linux.c + src/detection/packages/packages_linux.c + src/detection/packages/packages_nix.c + src/detection/poweradapter/poweradapter_nosupport.c + src/detection/processes/processes_linux.c + src/detection/gtk_qt/qt.c + src/detection/sound/sound_linux.c + src/detection/swap/swap_linux.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/tpm/tpm_nosupport.c + src/detection/uptime/uptime_linux.c + src/detection/users/users_linux.c + src/detection/wallpaper/wallpaper_linux.c + src/detection/wifi/wifi_nosupport.c + src/detection/wm/wm_linux.c + src/detection/de/de_linux.c + src/detection/wmtheme/wmtheme_linux.c + src/detection/camera/camera_nosupport.c + src/detection/zpool/zpool_nosupport.c + src/util/platform/FFPlatform_unix.c + src/util/binary_linux.c + ) endif() if(ENABLE_DIRECTX_HEADERS) @@ -1315,6 +1395,10 @@ elseif(NetBSD) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/X11R7/lib -Wl,-rpath,/usr/pkg/lib") # ditto elseif(Haiku) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE) +elseif(GNU) + target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE) + # On Hurd PATH_MAX is not defined. Set an arbitrary limit as workaround. + target_compile_definitions(libfastfetch PUBLIC PATH_MAX=4096) endif() if(FreeBSD OR OpenBSD OR NetBSD) @@ -1639,6 +1723,10 @@ elseif(SunOS) PRIVATE "nvpair" PRIVATE "devinfo" ) +elseif(GNU) + target_link_libraries(libfastfetch + PRIVATE "m" + ) elseif(ANDROID) CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC) if(HAVE_LIBANDROID_WORDEXP_STATIC) diff --git a/src/common/netif/netif_gnu.c b/src/common/netif/netif_gnu.c new file mode 100644 index 0000000000..b829af9cd7 --- /dev/null +++ b/src/common/netif/netif_gnu.c @@ -0,0 +1,35 @@ +#include "netif.h" +#include "common/io/io.h" + +#include +#include + +#define FF_STR_INDIR(x) #x +#define FF_STR(x) FF_STR_INDIR(x) + +bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result) +{ + FILE* FF_AUTO_CLOSE_FILE netRoute = fopen("/proc/route", "r"); + + if (!netRoute) return false; + + // skip first line + FF_UNUSED(fscanf(netRoute, "%*[^\n]\n")); + unsigned long long destination; //, gateway, flags, refCount, use, metric, mask, mtu, ... + while (fscanf(netRoute, "%" FF_STR(IF_NAMESIZE) "s%llx%*[^\n]", result->ifName, &destination) == 2) + { + if (destination != 0) continue; + result->ifIndex = if_nametoindex(result->ifName); + // TODO: Get the preferred source address + return true; + } + result->ifName[0] = '0'; + return false; +} + +bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result) +{ + // TODO: AF_INET6 + FF_UNUSED(result); + return false; +} diff --git a/src/common/networking/networking_linux.c b/src/common/networking/networking_linux.c index 074d4f528d..caf19accc4 100644 --- a/src/common/networking/networking_linux.c +++ b/src/common/networking/networking_linux.c @@ -22,7 +22,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state) if (!state->tfo) { - #ifdef __linux__ + #if __linux__ || __GNU__ // Linux doesn't support sendto() on unconnected sockets FF_DEBUG("TCP Fast Open disabled, skipping"); return "TCP Fast Open disabled"; @@ -34,7 +34,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state) #ifndef __APPLE__ // On macOS, TCP_FASTOPEN doesn't seem to be needed // Set TCP Fast Open - #ifdef __linux__ + #if __linux__ || __GNU__ int flag = 5; // the queue length of pending packets #else int flag = 1; // enable TCP Fast Open @@ -50,7 +50,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state) FF_DEBUG("Failed to set TCP_FASTOPEN option: %s", strerror(errno)); return "setsockopt(TCP_FASTOPEN) failed"; } else { - #ifdef __linux__ + #if __linux__ || __GNU__ FF_DEBUG("Successfully set TCP_FASTOPEN option, queue length: %d", flag); #elif defined(__APPLE__) FF_DEBUG("Successfully set TCP_FASTOPEN_FORCE_ENABLE option"); diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index 1fdfbae2a6..6a8ff72856 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -234,7 +234,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons assert(processName->length > 0); ffStrbufClear(exe); - #ifdef __linux__ + #if defined(__linux__) || defined(__GNU__) char filePath[64]; snprintf(filePath, sizeof(filePath), "/proc/%d/cmdline", (int)pid); @@ -436,33 +436,54 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i if (pid <= 0) return "Invalid pid"; - #ifdef __linux__ + #if defined(__linux__) || defined(__GNU__) char procFilePath[64]; - if (ppid) + #if __linux__ + if (ppid || tty) + #endif { snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/stat", (int)pid); char buf[PROC_FILE_BUFFSIZ]; ssize_t nRead = ffReadFileData(procFilePath, sizeof(buf) - 1, buf); if(nRead <= 8) return "ffReadFileData(/proc/pid/stat, PROC_FILE_BUFFSIZ-1, buf) failed"; - buf[nRead] = '\0'; + buf[nRead] = '\0'; // pid (comm) state ppid pgrp session tty - *ppid = 0; - static_assert(sizeof(*ppid) == sizeof(int), ""); + const char* pState = NULL; - ffStrbufEnsureFixedLengthFree(name, 255); - int tty_; - if( - sscanf(buf, "%*s (%255[^)]) %*c %d %*d %*d %d", name->chars, ppid, &tty_) < 2 || //stat (comm) state ppid pgrp session tty - name->chars[0] == '\0' - ) - return "sscanf(stat) failed"; + { + // comm in `/proc/pid/stat` is not encoded, and may contain ' ', ')' or even `\n` + const char* start = memchr(buf, '(', (size_t) nRead); + if (!start) + return "memchr(stat, '(') failed"; + start++; + const char* end = memrchr(start, ')', (size_t) nRead - (size_t) (start - buf)); + if (!end) + return "memrchr(stat, ')') failed"; + ffStrbufSetNS(name, (uint32_t) (end - start), start); + ffStrbufTrimRightSpace(name); + pState = end + 2; // skip ") " + } - ffStrbufRecalculateLength(name); - if (tty) - *tty = tty_ & 0xFF; + #if !__linux__ + if (ppid || tty) + #endif + { + int ppid_, tty_; + if( + sscanf(pState + 2, "%d %*d %*d %d", &ppid_, &tty_) < 2 || + name->chars[0] == '\0' + ) + return "sscanf(stat) failed"; + + if (ppid) + *ppid = (pid_t) ppid_; + if (tty) + *tty = tty_ & 0xFF; + } } + #if __linux__ else { snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/comm", (int)pid); @@ -471,6 +492,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i return "ffReadFileBuffer(/proc/pid/comm, name) failed"; ffStrbufTrimRightSpace(name); } + #endif #elif defined(__APPLE__) diff --git a/src/detection/cpu/cpu.h b/src/detection/cpu/cpu.h index bfdc43c0e1..9c4d8d5bad 100644 --- a/src/detection/cpu/cpu.h +++ b/src/detection/cpu/cpu.h @@ -97,7 +97,7 @@ inline static void ffCPUDetectByCpuid(FFCPUResult* cpu) #else -inline static void ffCPUDetectByCpuid(FFCPUResult* cpu) +inline static void ffCPUDetectByCpuid(FF_MAYBE_UNUSED FFCPUResult* cpu) { // Unsupported platform } diff --git a/src/detection/cpuusage/cpuusage.c b/src/detection/cpuusage/cpuusage.c index b9b944d323..40e569528b 100644 --- a/src/detection/cpuusage/cpuusage.c +++ b/src/detection/cpuusage/cpuusage.c @@ -54,6 +54,7 @@ const char* ffGetCpuUsageResult(FFCPUUsageOptions* options, FFlist* result) ffTimeSleep(options->waitTime); goto retry; } + return "CPU time did not increase. Try increasing wait time."; } } diff --git a/src/detection/diskio/diskio_linux.c b/src/detection/diskio/diskio_linux.c index 4d8d622419..f07b063c5e 100644 --- a/src/detection/diskio/diskio_linux.c +++ b/src/detection/diskio/diskio_linux.c @@ -23,8 +23,8 @@ static const char* parseDiskIOCounters(int dfd, const char* devName, FFlist* res ffStrbufAppendC(&name, ' '); } - if (ffAppendFileBufferRelative(devfd, "model", &name)) - ffStrbufTrimRightSpace(&name); + ffAppendFileBufferRelative(devfd, "model", &name); + ffStrbufTrimRightSpace(&name); if (name.length == 0) ffStrbufSetS(&name, devName); diff --git a/src/detection/displayserver/linux/wayland/wayland.c b/src/detection/displayserver/linux/wayland/wayland.c index f64d186324..843bab93a3 100644 --- a/src/detection/displayserver/linux/wayland/wayland.c +++ b/src/detection/displayserver/linux/wayland/wayland.c @@ -26,9 +26,9 @@ static bool waylandDetectWM(int fd, FFDisplayServerResult* result) { -#if __linux__ || (__FreeBSD__ && !__DragonFly__) +#if __linux__ || __GNU__ || (__FreeBSD__ && !__DragonFly__) -#if __linux +#if __linux__ || __GNU__ struct ucred ucred = {}; socklen_t len = sizeof(ucred); if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1 || ucred.pid <= 0) diff --git a/src/detection/displayserver/linux/wmde.c b/src/detection/displayserver/linux/wmde.c index f735bd40c0..8310c4bc9a 100644 --- a/src/detection/displayserver/linux/wmde.c +++ b/src/detection/displayserver/linux/wmde.c @@ -351,7 +351,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result) break; } } -#elif __linux__ +#elif __linux__ || __GNU__ FF_AUTO_CLOSE_DIR DIR* procdir = opendir("/proc"); if(procdir == NULL) return "opendir(\"/proc\") failed"; diff --git a/src/detection/initsystem/initsystem_linux.c b/src/detection/initsystem/initsystem_linux.c index 6776ef7584..c727b39bff 100644 --- a/src/detection/initsystem/initsystem_linux.c +++ b/src/detection/initsystem/initsystem_linux.c @@ -48,7 +48,7 @@ const char* ffDetectInitSystem(FFInitSystemResult* result) if (instance.config.general.detectVersion) { - #if __linux__ && !__ANDROID__ + #if (defined(__linux__) && !defined(__ANDROID__)) || defined(__GNU__) if (ffStrbufEqualS(&result->name, "systemd")) { ffBinaryExtractStrings(result->exe.chars, extractSystemdVersion, &result->version, (uint32_t) strlen("systemd 0.0 running in x")); @@ -84,6 +84,20 @@ const char* ffDetectInitSystem(FFInitSystemResult* result) ffStrbufSubstrAfterLastC(&result->version, ' '); } } + else if (ffStrbufEqualS(&result->name, "guile")) + { + // TODO: guile is actually shepherd + if (ffProcessAppendStdOut(&result->version, (char* const[]) { + ffStrbufEndsWithS(&result->exe, "/guile") ? result->exe.chars : "guile", + "--version", + NULL, + }) == NULL && result->version.length) + { + // guile (GNU Guile) 3.0.9 + ffStrbufSubstrBeforeFirstC(&result->version, '\n'); + ffStrbufSubstrAfterLastC(&result->version, ' '); + } + } #elif __APPLE__ if (ffStrbufEqualS(&result->name, "launchd")) { diff --git a/src/detection/loadavg/loadavg_linux.c b/src/detection/loadavg/loadavg_linux.c index 9e8b091c57..c75afb9622 100644 --- a/src/detection/loadavg/loadavg_linux.c +++ b/src/detection/loadavg/loadavg_linux.c @@ -19,7 +19,7 @@ const char* ffDetectLoadavg(double result[3]) } #endif - + #ifndef __GNU__ // getloadavg requires higher ANDROID_API version struct sysinfo si; if (sysinfo(&si) < 0) @@ -27,5 +27,6 @@ const char* ffDetectLoadavg(double result[3]) for (int i = 0; i < 3; i++) result[i] = (double) si.loads[i] / (1 << SI_LOAD_SHIFT); + #endif return NULL; } diff --git a/src/detection/localip/localip_linux.c b/src/detection/localip/localip_linux.c index ad96452298..36604bd206 100644 --- a/src/detection/localip/localip_linux.c +++ b/src/detection/localip/localip_linux.c @@ -29,7 +29,7 @@ #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__) || defined(__HAIKU__) #include #include -#else +#elif !defined(__GNU__) #include #endif #if defined(__sun) || defined(__HAIKU__) @@ -69,12 +69,14 @@ static const FFLocalIpNIFlag niFlagOptions[] = { #ifdef IFF_NOTRAILERS FF_LOCALIP_NIFLAG(NOTRAILERS), #endif -#ifdef __linux__ +#if defined( __linux__) || defined (__GNU__) FF_LOCALIP_NIFLAG(MASTER), FF_LOCALIP_NIFLAG(SLAVE), FF_LOCALIP_NIFLAG(PORTSEL), FF_LOCALIP_NIFLAG(AUTOMEDIA), FF_LOCALIP_NIFLAG(DYNAMIC), +#endif +#ifdef __linux__ FF_LOCALIP_NIFLAG(LOWER_UP), FF_LOCALIP_NIFLAG(DORMANT), FF_LOCALIP_NIFLAG(ECHO), @@ -396,7 +398,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) adapter->mac = ifa; FF_DEBUG("Updated MAC entry for interface %s", ifa->ifa_name); break; - #elif !__sun + #elif !__sun && !__GNU__ case AF_PACKET: adapter->mac = ifa; FF_DEBUG("Updated MAC entry for interface %s", ifa->ifa_name); @@ -543,7 +545,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) } } mac: - #ifndef __sun + #if !defined( __sun) && !defined(__GNU__) if (options->showType & FF_LOCALIP_TYPE_MAC_BIT) { if (adapter->mac->ifa_addr) @@ -1006,14 +1008,16 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) #endif } - #ifdef __sun + #if __sun || __GNU__ if ((options->showType & FF_LOCALIP_TYPE_MAC_BIT) && ioctl(sockfd, SIOCGIFHWADDR, &ifr) == 0) { const uint8_t* ptr = (uint8_t*) ifr.ifr_addr.sa_data; // NOT ifr_enaddr ffStrbufSetF(&iface->mac, "%02x:%02x:%02x:%02x:%02x:%02x", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]); - FF_DEBUG("Added MAC address %s for interface %s (Solaris)", iface->mac.chars, iface->name.chars); + FF_DEBUG("Added MAC address %s for interface %s (Solaris/GNU)", iface->mac.chars, iface->name.chars); } + #endif + #if __sun if (options->showType & FF_LOCALIP_TYPE_SPEED_BIT) { __attribute__((__cleanup__(kstatFreeWrap))) kstat_ctl_t* kc = kstat_open(); diff --git a/src/detection/os/os_linux.c b/src/detection/os/os_linux.c index 9b5ef3690f..376bf8d343 100644 --- a/src/detection/os/os_linux.c +++ b/src/detection/os/os_linux.c @@ -370,7 +370,7 @@ void ffDetectOSImpl(FFOSResult* os) { detectOS(os); - #ifdef __linux__ + #if __linux__ || __GNU__ if(ffStrbufEqualS(&os->id, "ubuntu")) getUbuntuFlavour(os); else if(ffStrbufEqualS(&os->id, "debian")) diff --git a/src/detection/packages/packages.h b/src/detection/packages/packages.h index 21e5ba5446..7464a30c17 100644 --- a/src/detection/packages/packages.h +++ b/src/detection/packages/packages.h @@ -55,7 +55,7 @@ const char* ffDetectPackages(FFPackagesResult* result, FFPackagesOptions* option bool ffPackagesReadCache(FFstrbuf* cacheDir, FFstrbuf* cacheContent, const char* filePath, const char* packageId, uint32_t* result); bool ffPackagesWriteCache(FFstrbuf* cacheDir, FFstrbuf* cacheContent, uint32_t num_elements); -#if defined(__linux__) || defined(__APPLE__) +#if defined(__linux__) || defined(__APPLE__) || defined(__GNU__) uint32_t ffPackagesGetNix(FFstrbuf* baseDir, const char* dirname); #endif #ifndef _WIN32 diff --git a/src/detection/packages/packages_linux.c b/src/detection/packages/packages_linux.c index fbd607413c..95e117548f 100644 --- a/src/detection/packages/packages_linux.c +++ b/src/detection/packages/packages_linux.c @@ -517,7 +517,6 @@ void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options) #endif ffStrbufSet(&baseDir, &instance.state.platform.homeDir); - if (!(options->disabled & FF_PACKAGES_FLAG_NIX_BIT)) { // Count packages from $HOME/.nix-profile diff --git a/src/detection/swap/swap_haiku.c b/src/detection/swap/swap_haiku.c index b483668b36..990e741fd7 100644 --- a/src/detection/swap/swap_haiku.c +++ b/src/detection/swap/swap_haiku.c @@ -16,7 +16,7 @@ const char* ffDetectSwap(FFlist* result) if (kvms) { const char* swapAuto = get_driver_parameter(kvms, "swap_auto", NULL, NULL); - if (swapAuto) + if (swapAuto) ffStrbufSetStatic(&swap->name, swapAuto[0] == 'y' ? "Auto" : "Manual"); unload_driver_settings(kvms); } diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index d2d2b74386..48476b63a7 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -580,10 +580,10 @@ static bool getTerminalVersionZed(FFstrbuf* exe, FFstrbuf* version) #ifndef _WIN32 static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version) { - #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__GNU__) char buffer[1024] = {}; if ( - #ifdef __linux__ + #if __linux__ || __GNU__ ffReadFileData(FASTFETCH_TARGET_DIR_USR "/lib64/kitty/kitty/constants.py", ARRAY_SIZE(buffer) - 1, buffer) || ffReadFileData(FASTFETCH_TARGET_DIR_USR "/lib/kitty/kitty/constants.py", ARRAY_SIZE(buffer) - 1, buffer) #else @@ -768,7 +768,7 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe #endif - #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) || defined(__HAIKU__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__) if(ffStrbufStartsWithIgnCaseS(processName, "gnome-terminal")) return getTerminalVersionGnome(exe, version); diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 7d739ca7a9..0f50b04521 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -240,7 +240,7 @@ static void getTerminalFromEnv(FFTerminalResult* result) } #endif - #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__GNU__) //Konsole else if( getenv("KONSOLE_VERSION") != NULL @@ -333,7 +333,7 @@ static void setTerminalInfoDetails(FFTerminalResult* result) else if(ffStrbufEqualS(&result->processName, "com.termux")) ffStrbufInitStatic(&result->prettyName, "Termux"); - #elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) + #elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__GNU__) else if(ffStrbufStartsWithS(&result->processName, "gnome-terminal")) ffStrbufInitStatic(&result->prettyName, "GNOME Terminal"); diff --git a/src/detection/uptime/uptime_linux.c b/src/detection/uptime/uptime_linux.c index 44705a5fcf..1007374ce6 100644 --- a/src/detection/uptime/uptime_linux.c +++ b/src/detection/uptime/uptime_linux.c @@ -26,13 +26,15 @@ const char* ffDetectUptime(FFUptimeResult* result) } #endif - + #ifndef __GNU__ struct timespec uptime; if (clock_gettime(CLOCK_BOOTTIME, &uptime) != 0) return "clock_gettime(CLOCK_BOOTTIME) failed"; result->uptime = (uint64_t) uptime.tv_sec * 1000 + (uint64_t) uptime.tv_nsec / 1000000; result->bootTime = ffTimeGetNow() - result->uptime; - return NULL; + #else + return "read(/proc/uptime) failed"; + #endif } diff --git a/src/detection/users/users_linux.c b/src/detection/users/users_linux.c index 99e27627c2..acf860d774 100644 --- a/src/detection/users/users_linux.c +++ b/src/detection/users/users_linux.c @@ -10,7 +10,7 @@ #define setutxent setutent #define getutxent getutent #endif -#ifdef __linux__ +#if __linux__ || __GNU__ #include #include #endif @@ -40,7 +40,7 @@ const char* ffDetectUsers(FFUsersOptions* options, FFlist* users) ffStrbufInitS(&user->hostName, n->ut_host); ffStrbufInitS(&user->sessionName, n->ut_line); ffStrbufInit(&user->clientIp); - #ifdef __linux__ + #if __linux__ || __GNU__ bool isIpv6 = false; for (int i = 1; i < 4; ++i) { if (n->ut_addr_v6[i] != 0) { diff --git a/src/detection/version/version.c b/src/detection/version/version.c index f47ffcaa16..7d278107e7 100644 --- a/src/detection/version/version.c +++ b/src/detection/version/version.c @@ -54,6 +54,8 @@ #define FF_SYSNAME "NetBSD" #elif defined(__HAIKU__) #define FF_SYSNAME "Haiku" +#elif defined(__GNU__) + #define FF_SYSNAME "GNU" #else #define FF_SYSNAME "Unknown" #endif diff --git a/src/options/general.c b/src/options/general.c index 72f79798bb..128d917998 100644 --- a/src/options/general.c +++ b/src/options/general.c @@ -30,7 +30,7 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va else if (unsafe_yyjson_equals_str(key, "detectVersion")) options->detectVersion = yyjson_get_bool(val); - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__) else if (unsafe_yyjson_equals_str(key, "playerName")) ffStrbufSetJsonVal(&options->playerName, val); else if (unsafe_yyjson_equals_str(key, "dsForceDrm")) @@ -73,7 +73,7 @@ bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key else if(ffStrEqualsIgnCase(key, "--detect-version")) options->detectVersion = ffOptionParseBoolean(value); - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__) else if(ffStrEqualsIgnCase(key, "--player-name")) ffOptionParseString(key, value, &options->playerName); else if(ffStrEqualsIgnCase(key, "--ds-force-drm")) @@ -102,7 +102,7 @@ void ffOptionsInitGeneral(FFOptionsGeneral* options) options->multithreading = true; options->detectVersion = true; - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__) ffStrbufInit(&options->playerName); options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_FALSE; #elif defined(_WIN32) @@ -112,7 +112,7 @@ void ffOptionsInitGeneral(FFOptionsGeneral* options) void ffOptionsDestroyGeneral(FF_MAYBE_UNUSED FFOptionsGeneral* options) { - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__) ffStrbufDestroy(&options->playerName); #endif } @@ -127,7 +127,7 @@ void ffOptionsGenerateGeneralJsonConfig(FFOptionsGeneral* options, yyjson_mut_do yyjson_mut_obj_add_bool(doc, obj, "detectVersion", options->detectVersion); - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__) yyjson_mut_obj_add_strbuf(doc, obj, "playerName", &options->playerName); diff --git a/src/options/general.h b/src/options/general.h index 9e703a946b..0edcfeb2d5 100644 --- a/src/options/general.h +++ b/src/options/general.h @@ -16,7 +16,7 @@ typedef struct FFOptionsGeneral bool detectVersion; // Module options that cannot be put in module option structure - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__) FFstrbuf playerName; FFDsForceDrmType dsForceDrm; #elif defined(_WIN32) diff --git a/src/util/apple/Info.plist.in b/src/util/apple/Info.plist.in index 9e24ccb7c3..52200538b6 100644 --- a/src/util/apple/Info.plist.in +++ b/src/util/apple/Info.plist.in @@ -6,8 +6,8 @@ fastfetch CFBundleName @PROJECT_NAME@ - CFBundleShortVersionString - @PROJECT_VERSION@ + CFBundleShortVersionString + @PROJECT_VERSION@ CFBundleDevelopmentRegion English NSBluetoothAlwaysUsageDescription diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index eb9ee450e8..682c2e6f73 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -22,7 +22,7 @@ static void getExePath(FFPlatform* platform) { char exePath[PATH_MAX + 1]; - #ifdef __linux__ + #if defined(__linux__) || defined (__GNU__) ssize_t exePathLen = readlink("/proc/self/exe", exePath, sizeof(exePath) - 1); if (exePathLen >= 0) exePath[exePathLen] = '\0'; diff --git a/src/util/smbiosHelper.c b/src/util/smbiosHelper.c index 87569515f0..593527a72f 100644 --- a/src/util/smbiosHelper.c +++ b/src/util/smbiosHelper.c @@ -52,7 +52,7 @@ const FFSmbiosHeader* ffSmbiosNextEntry(const FFSmbiosHeader* header) return (const FFSmbiosHeader*) (p + 1); } -#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__) || defined(__OpenBSD__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__) || defined(__OpenBSD__) || defined(__GNU__) #include #include #include @@ -143,7 +143,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable() { FF_DEBUG("Initializing SMBIOS buffer"); ffStrbufInit(&buffer); - #if !__HAIKU__ && !__OpenBSD__ && !__DragonFly__ + #if !__HAIKU__ && !__OpenBSD__ && !__DragonFly__ && !__GNU__ #ifdef __linux__ FF_DEBUG("Using Linux implementation - trying /sys/firmware/dmi/tables/DMI"); if (!ffAppendFileBuffer("/sys/firmware/dmi/tables/DMI", &buffer))