From 4665fdd1459a3ac769e987b50160283678a99fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 27 Oct 2024 11:43:36 +0800 Subject: [PATCH] Global: make it compile on NetBSD Doesn't work yet. --- .gitignore | 1 + CMakeLists.txt | 87 +++++++++++++++++++ src/common/init.c | 2 +- src/common/processing_linux.c | 55 ++++++++++-- src/detection/bios/bios_nbsd.c | 15 ++++ src/detection/board/board_nbsd.c | 15 ++++ src/detection/chassis/chassis_nbsd.c | 15 ++++ src/detection/cpu/cpu_bsd.c | 7 +- src/detection/host/host_nbsd.c | 17 ++++ src/detection/loadavg/loadavg_bsd.c | 2 +- src/detection/localip/localip_linux.c | 8 +- src/detection/memory/memory_bsd.c | 8 +- src/detection/os/os_nbsd.c | 7 ++ src/detection/processes/processes_nosupport.c | 6 ++ src/detection/terminalshell/terminalshell.c | 8 +- .../terminalshell/terminalshell_linux.c | 4 +- src/options/general.c | 6 +- src/options/general.h | 2 +- src/util/binary_linux.c | 2 +- src/util/platform/FFPlatform_unix.c | 12 ++- 20 files changed, 252 insertions(+), 27 deletions(-) create mode 100644 src/detection/bios/bios_nbsd.c create mode 100644 src/detection/board/board_nbsd.c create mode 100644 src/detection/chassis/chassis_nbsd.c create mode 100644 src/detection/host/host_nbsd.c create mode 100644 src/detection/os/os_nbsd.c create mode 100644 src/detection/processes/processes_nosupport.c diff --git a/.gitignore b/.gitignore index 2d69a508..35828e87 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ tags fastfetch.kdev4 *.user *.user.* +*.swp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e5cfede..c3d69a62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,8 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") set(FreeBSD TRUE CACHE BOOL "..." FORCE) elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD") set(OpenBSD TRUE CACHE BOOL "..." FORCE) +elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "NetBSD") + set(NetBSD TRUE CACHE BOOL "..." FORCE) elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") set(SunOS TRUE CACHE BOOL "..." FORCE) elseif(NOT APPLE AND NOT WIN32) @@ -663,6 +665,88 @@ elseif(FreeBSD) src/util/platform/FFPlatform_unix.c src/util/binary_linux.c ) +elseif(NetBSD) + list(APPEND LIBFASTFETCH_SRC + src/common/dbus.c + src/common/io/io_unix.c + src/common/netif/netif_bsd.c + src/common/networking_linux.c + src/common/processing_linux.c + src/common/sysctl.c + src/detection/battery/battery_nosupport.c + src/detection/bios/bios_nbsd.c + src/detection/bluetooth/bluetooth_linux.c + src/detection/bluetoothradio/bluetoothradio_linux.c + src/detection/board/board_nbsd.c + src/detection/bootmgr/bootmgr_nosupport.c + src/detection/brightness/brightness_bsd.c + src/detection/btrfs/btrfs_nosupport.c + src/detection/chassis/chassis_nbsd.c + src/detection/cpu/cpu_bsd.c + src/detection/cpucache/cpucache_nosupport.c + src/detection/cpuusage/cpuusage_nosupport.c + src/detection/cursor/cursor_linux.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/kde-output.c + src/detection/displayserver/linux/wayland/wlr-output-management-unstable-v1-protocol.c + src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c + src/detection/displayserver/linux/wayland/kde-output-order-v1-protocol.c + src/detection/displayserver/linux/wayland/xdg-output-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_nbsd.c + src/detection/lm/lm_linux.c + src/detection/icons/icons_linux.c + src/detection/initsystem/initsystem_linux.c + src/detection/keyboard/keyboard_nosupport.c + src/detection/libc/libc_nosupport.c + src/detection/loadavg/loadavg_bsd.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_bsd.c + src/detection/mouse/mouse_nosupport.c + src/detection/netio/netio_nosupport.c + src/detection/opengl/opengl_linux.c + src/detection/os/os_nbsd.c + src/detection/packages/packages_nosupport.c + src/detection/poweradapter/poweradapter_nosupport.c + src/detection/processes/processes_nosupport.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/tpm/tpm_nosupport.c + src/detection/uptime/uptime_bsd.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_linux.c + src/detection/zpool/zpool_linux.c + src/util/platform/FFPlatform_unix.c + src/util/binary_linux.c + ) elseif(OpenBSD) list(APPEND LIBFASTFETCH_SRC src/common/dbus.c @@ -1054,6 +1138,9 @@ elseif(OpenBSD) target_compile_definitions(libfastfetch PUBLIC _XOPEN_SOURCE=700 _FILE_OFFSET_BITS=64 _BSD_SOURCE) elseif(SunOS) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 __EXTENSIONS__ _POSIX_C_SOURCE) +elseif(NetBSD) + target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-char-subscripts") endif() if(HAVE_STATX) diff --git a/src/common/init.c b/src/common/init.c index 643f94a9..96117c66 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -245,7 +245,7 @@ void ffListFeatures(void) #if FF_HAVE_DDCUTIL "libddcutil\n" #endif - #if FF_HAVE_ELF || __sun || __FreeBSD__ || __OpenBSD__ + #if FF_HAVE_ELF || __sun || __FreeBSD__ || __OpenBSD__ || __NetBSD__ "libelf\n" #endif #if FF_HAVE_LIBZFS diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index 0e6a243c..b9045bb6 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -23,9 +23,12 @@ #elif defined(__sun) #include #elif defined(__OpenBSD__) -#include -#include -#include + #include + #include + #include +#elif defined(__NetBSD__) + #include + #include #endif enum { FF_PIPE_BUFSIZ = 8192 }; @@ -202,7 +205,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons } } - #elif defined(__FreeBSD__) + #elif defined(__FreeBSD__) || defined(__NetBSD__) size_t size = ARG_MAX; FF_AUTO_FREE char* args = malloc(size); @@ -210,7 +213,13 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons static_assert(ARG_MAX > PATH_MAX, ""); if(exePath && sysctl( - (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, pid}, 4, + (int[]){CTL_KERN, + #if __FreeBSD__ + KERN_PROC, + #else + KERN_PROC_ARGS, + #endif + KERN_PROC_PATHNAME, pid}, 4, args, &size, NULL, 0 ) == 0) @@ -218,7 +227,13 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons size = ARG_MAX; if(sysctl( - (int[]){CTL_KERN, KERN_PROC, KERN_PROC_ARGS, pid}, 4, + (int[]){CTL_KERN, + #if __FreeBSD__ + KERN_PROC, KERN_PROC_ARGS, + #else + KERN_PROC_ARGS, KERN_PROC_ARGV, + #endif + pid}, 4, args, &size, NULL, 0 ) == 0) @@ -378,6 +393,34 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i *tty = -1; } + #elif defined(__NetBSD__) + + struct kinfo_proc2 proc; + size_t size = sizeof(proc); + if(sysctl( + (int[]){CTL_KERN, KERN_PROC2, KERN_PROC_PID, pid}, 4, + &proc, &size, + NULL, 0 + )) + return "sysctl(KERN_PROC_PID) failed"; + + ffStrbufSetS(name, proc.p_comm); + if (ppid) + *ppid = (pid_t)proc.p_ppid; + if (tty) + { + if (proc.p_flag & P_CONTROLT) + { + const char* ttyName = devname(proc.p_tdev, S_IFCHR); + if (ffStrStartsWith(ttyName, "pts/")) + *tty = (int32_t) strtol(ttyName + strlen("pts/"), NULL, 10); + else + *tty = -1; + } + else + *tty = -1; + } + #elif defined(__sun) char path[128]; snprintf(path, sizeof(path), "/proc/%d/psinfo", (int) pid); diff --git a/src/detection/bios/bios_nbsd.c b/src/detection/bios/bios_nbsd.c new file mode 100644 index 00000000..056eb2d4 --- /dev/null +++ b/src/detection/bios/bios_nbsd.c @@ -0,0 +1,15 @@ +#include "bios.h" +#include "common/sysctl.h" +#include "util/smbiosHelper.h" + +const char* ffDetectBios(FFBiosResult* bios) +{ + if (ffSysctlGetString("machdep.dmi.bios-date", &bios->date) == NULL) + ffCleanUpSmbiosValue(&bios->date); + if (ffSysctlGetString("machdep.dmi.bios-version", &bios->version) == NULL) + ffCleanUpSmbiosValue(&bios->version); + if (ffSysctlGetString("machdep.dmi.bios-vendor", &bios->vendor) == NULL) + ffCleanUpSmbiosValue(&bios->vendor); + + return NULL; +} diff --git a/src/detection/board/board_nbsd.c b/src/detection/board/board_nbsd.c new file mode 100644 index 00000000..9557cc33 --- /dev/null +++ b/src/detection/board/board_nbsd.c @@ -0,0 +1,15 @@ +#include "board.h" +#include "common/sysctl.h" +#include "util/smbiosHelper.h" + +const char* ffDetectBoard(FFBoardResult* board) +{ + if (ffSysctlGetString("machdep.dmi.board-product", &board->name) == NULL) + ffCleanUpSmbiosValue(&board->name); + if (ffSysctlGetString("machdep.dmi.board-version", &board->version) == NULL) + ffCleanUpSmbiosValue(&board->version); + if (ffSysctlGetString("machdep.dmi.board-vendor", &board->vendor) == NULL) + ffCleanUpSmbiosValue(&board->vendor); + + return NULL; +} diff --git a/src/detection/chassis/chassis_nbsd.c b/src/detection/chassis/chassis_nbsd.c new file mode 100644 index 00000000..796c241a --- /dev/null +++ b/src/detection/chassis/chassis_nbsd.c @@ -0,0 +1,15 @@ +#include "chassis.h" +#include "common/sysctl.h" +#include "util/smbiosHelper.h" + +const char* ffDetectChassis(FFChassisResult* chassis) +{ + if (ffSysctlGetString("machdep.dmi.chassis-type", &chassis->type) == NULL) + ffCleanUpSmbiosValue(&chassis->type); + if (ffSysctlGetString("machdep.dmi.chassis-version", &chassis->version) == NULL) + ffCleanUpSmbiosValue(&chassis->version); + if (ffSysctlGetString("machdep.dmi.chassis-vendor", &chassis->vendor) == NULL) + ffCleanUpSmbiosValue(&chassis->vendor); + + return NULL; +} diff --git a/src/detection/cpu/cpu_bsd.c b/src/detection/cpu/cpu_bsd.c index 961cb847..7bf46407 100644 --- a/src/detection/cpu/cpu_bsd.c +++ b/src/detection/cpu/cpu_bsd.c @@ -25,8 +25,13 @@ static const char* detectThermalTemp(double* current) const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) { - if (ffSysctlGetString("hw.model", &cpu->name)) + #if __NetBSD__ + if (ffSysctlGetString("machdep.cpu_brand", &cpu->name) != NULL) + return "sysctlbyname(machdep.cpu_brand) failed"; + #else + if (ffSysctlGetString("hw.model", &cpu->name) != NULL) return "sysctlbyname(hw.model) failed"; + #endif cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1); cpu->coresLogical = cpu->coresPhysical; diff --git a/src/detection/host/host_nbsd.c b/src/detection/host/host_nbsd.c new file mode 100644 index 00000000..947198cb --- /dev/null +++ b/src/detection/host/host_nbsd.c @@ -0,0 +1,17 @@ +#include "host.h" +#include "common/sysctl.h" +#include "util/smbiosHelper.h" + +const char* ffDetectHost(FFHostResult* host) +{ + const char* error = NULL; + if ((error = ffSysctlGetString("machdep.dmi.system-product", &host->name))) + return error; + ffCleanUpSmbiosValue(&host->name); + if (ffSysctlGetString("machdep.dmi.system-vendor", &host->vendor) == NULL) + ffCleanUpSmbiosValue(&host->vendor); + if (ffSysctlGetString("machdep.dmi.system-version", &host->version) == NULL) + ffCleanUpSmbiosValue(&host->version); + + return NULL; +} diff --git a/src/detection/loadavg/loadavg_bsd.c b/src/detection/loadavg/loadavg_bsd.c index 3a0b6bca..ca7b17ca 100644 --- a/src/detection/loadavg/loadavg_bsd.c +++ b/src/detection/loadavg/loadavg_bsd.c @@ -2,7 +2,7 @@ #include -#if __FreeBSD__ || __OpenBSD__ +#if __FreeBSD__ || __OpenBSD__ || __NetBSD__ #include #include #if __FreeBSD__ diff --git a/src/detection/localip/localip_linux.c b/src/detection/localip/localip_linux.c index adf5713d..87d4acb2 100644 --- a/src/detection/localip/localip_linux.c +++ b/src/detection/localip/localip_linux.c @@ -18,7 +18,7 @@ #include #endif -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__) #include #include #else @@ -52,7 +52,7 @@ static const FFLocalIpNIFlag niFlagOptions[] = { { IFF_DORMANT, "DORMANT" }, { IFF_ECHO, "ECHO" }, #endif -#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) { IFF_OACTIVE, "OACTIVE" }, { IFF_SIMPLEX, "SIMPLEX" }, { IFF_LINK0, "LINK0" }, @@ -190,7 +190,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) addNewIp(results, ifa->ifa_name, addressBuffer, AF_INET6, isDefaultRoute, flags, !(options->showType & FF_LOCALIP_TYPE_ALL_IPS_BIT)); } - #if __FreeBSD__ || __OpenBSD__ || __APPLE__ + #if __FreeBSD__ || __OpenBSD__ || __APPLE__ || __NetBSD__ else if (ifa->ifa_addr->sa_family == AF_LINK) { if (!(options->showType & FF_LOCALIP_TYPE_MAC_BIT)) @@ -246,7 +246,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) ifr.ifr_data = (void*) &edata; if (ioctl(sockfd, SIOCETHTOOL, &ifr) == 0) iface->speed = (edata.speed_hi << 16) | edata.speed; // ethtool_cmd_speed is not available on Android - #elif __FreeBSD__ || __APPLE__ || __OpenBSD__ + #elif __FreeBSD__ || __APPLE__ || __OpenBSD__ || __NetBSD__ struct ifmediareq ifmr = {}; ffStrCopyN(ifmr.ifm_name, iface->name.chars, IFNAMSIZ); if (ioctl(sockfd, SIOCGIFMEDIA, &ifmr) == 0 && (IFM_TYPE(ifmr.ifm_active) & IFM_ETHER)) diff --git a/src/detection/memory/memory_bsd.c b/src/detection/memory/memory_bsd.c index 0db20527..587ca7f1 100644 --- a/src/detection/memory/memory_bsd.c +++ b/src/detection/memory/memory_bsd.c @@ -4,7 +4,13 @@ const char* ffDetectMemory(FFMemoryResult* ram) { size_t length = sizeof(ram->bytesTotal); - if (sysctl((int[]){ CTL_HW, HW_PHYSMEM }, 2, &ram->bytesTotal, &length, NULL, 0)) + if (sysctl((int[]){ CTL_HW, +#if __NetBSD__ + HW_PHYSMEM64 +#else + HW_PHYSMEM +#endif + }, 2, &ram->bytesTotal, &length, NULL, 0)) return "Failed to read hw.physmem"; // vm.stats.vm.* are int values diff --git a/src/detection/os/os_nbsd.c b/src/detection/os/os_nbsd.c new file mode 100644 index 00000000..229df96d --- /dev/null +++ b/src/detection/os/os_nbsd.c @@ -0,0 +1,7 @@ +#include "os.h" + +void ffDetectOSImpl(FFOSResult* os) +{ + ffStrbufSetStatic(&os->name, "NetBSD"); + ffStrbufSet(&os->version, &instance.state.platform.sysinfo.release); +} diff --git a/src/detection/processes/processes_nosupport.c b/src/detection/processes/processes_nosupport.c new file mode 100644 index 00000000..e1774dd0 --- /dev/null +++ b/src/detection/processes/processes_nosupport.c @@ -0,0 +1,6 @@ +#include "processes.h" + +const char* ffDetectProcesses(uint32_t* result) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index a68e3351..f2d322b7 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -10,6 +10,8 @@ #include #elif __OpenBSD__ #define _PATH_LOCALBASE "/usr/local" +#elif __NetBSD__ + #define _PATH_LOCALBASE "/usr/pkg" #endif #ifdef _WIN32 @@ -121,7 +123,7 @@ static bool getShellVersionPwsh(FFstrbuf* exe, FFstrbuf* version) static bool getShellVersionKsh(FFstrbuf* exe, FFstrbuf* version) { -#if __OpenBSD__ +#if __OpenBSD__ || __NetBSD__ if(ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "-c", @@ -575,7 +577,7 @@ static bool getTerminalVersionZed(FFstrbuf* exe, FFstrbuf* version) #ifndef _WIN32 static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version) { - #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) char buffer[1024] = {}; if ( #ifdef __linux__ @@ -678,7 +680,7 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe #endif - #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) 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 c29d9774..5d63236f 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -236,7 +236,7 @@ static void getTerminalFromEnv(FFTerminalResult* result) } #endif - #if defined(__linux__) || defined(__FreeBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) //Konsole else if( getenv("KONSOLE_VERSION") != NULL @@ -329,7 +329,7 @@ static void setTerminalInfoDetails(FFTerminalResult* result) else if(ffStrbufEqualS(&result->processName, "com.termux")) ffStrbufInitStatic(&result->prettyName, "Termux"); - #elif defined(__linux__) || defined(__FreeBSD__) + #elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) else if(ffStrbufStartsWithS(&result->processName, "gnome-terminal")) ffStrbufInitStatic(&result->prettyName, "GNOME Terminal"); diff --git a/src/options/general.c b/src/options/general.c index a29c2196..6f088256 100644 --- a/src/options/general.c +++ b/src/options/general.c @@ -39,7 +39,7 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va else if (ffStrEqualsIgnCase(key, "detectVersion")) options->detectVersion = yyjson_get_bool(val); - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) else if (ffStrEqualsIgnCase(key, "escapeBedrock")) options->escapeBedrock = yyjson_get_bool(val); else if (ffStrEqualsIgnCase(key, "playerName")) @@ -84,7 +84,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__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) else if(ffStrEqualsIgnCase(key, "--escape-bedrock")) options->escapeBedrock = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "--player-name")) @@ -115,7 +115,7 @@ void ffOptionsInitGeneral(FFOptionsGeneral* options) options->multithreading = true; options->detectVersion = true; - #if defined(__linux__) || defined(__FreeBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) options->escapeBedrock = true; ffStrbufInit(&options->playerName); options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_FALSE; diff --git a/src/options/general.h b/src/options/general.h index 0a85df76..f1f0f3ff 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__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) FFstrbuf playerName; bool escapeBedrock; FFDsForceDrmType dsForceDrm; diff --git a/src/util/binary_linux.c b/src/util/binary_linux.c index b9c521ca..1d520ca3 100644 --- a/src/util/binary_linux.c +++ b/src/util/binary_linux.c @@ -1,6 +1,6 @@ #include "binary.h" -#if defined(FF_HAVE_ELF) || defined(__sun) || defined(__FreeBSD__) || defined(__OpenBSD__) +#if defined(FF_HAVE_ELF) || defined(__sun) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) #include "common/io/io.h" #include "common/library.h" diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index 9eaeae38..ff5fe5b7 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -12,7 +12,7 @@ #ifdef __APPLE__ #include #include -#elif defined(__FreeBSD__) || defined(__OpenBSD__) +#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) #include #endif @@ -24,10 +24,16 @@ static void getExePath(FFPlatform* platform) exePath[exePathLen] = '\0'; #elif defined(__APPLE__) int exePathLen = proc_pidpath((int) getpid(), exePath, sizeof(exePath)); - #elif defined(__FreeBSD__) + #elif defined(__FreeBSD__) || defined(__NetBSD__) size_t exePathLen = sizeof(exePath); if(sysctl( - (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, (int) getpid()}, 4, + (int[]){CTL_KERN, + #ifdef __FreeBSD__ + KERN_PROC, + #else + KERN_PROC_ARGS, + #endif + KERN_PROC_PATHNAME, (int) getpid()}, 4, exePath, &exePathLen, NULL, 0 ) < 0)