Skip to content

Commit 4665fdd

Browse files
committed
Global: make it compile on NetBSD
Doesn't work yet.
1 parent 2fe6e60 commit 4665fdd

File tree

20 files changed

+252
-27
lines changed

20 files changed

+252
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ tags
99
fastfetch.kdev4
1010
*.user
1111
*.user.*
12+
*.swp

CMakeLists.txt

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
2020
set(FreeBSD TRUE CACHE BOOL "..." FORCE)
2121
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
2222
set(OpenBSD TRUE CACHE BOOL "..." FORCE)
23+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "NetBSD")
24+
set(NetBSD TRUE CACHE BOOL "..." FORCE)
2325
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
2426
set(SunOS TRUE CACHE BOOL "..." FORCE)
2527
elseif(NOT APPLE AND NOT WIN32)
@@ -663,6 +665,88 @@ elseif(FreeBSD)
663665
src/util/platform/FFPlatform_unix.c
664666
src/util/binary_linux.c
665667
)
668+
elseif(NetBSD)
669+
list(APPEND LIBFASTFETCH_SRC
670+
src/common/dbus.c
671+
src/common/io/io_unix.c
672+
src/common/netif/netif_bsd.c
673+
src/common/networking_linux.c
674+
src/common/processing_linux.c
675+
src/common/sysctl.c
676+
src/detection/battery/battery_nosupport.c
677+
src/detection/bios/bios_nbsd.c
678+
src/detection/bluetooth/bluetooth_linux.c
679+
src/detection/bluetoothradio/bluetoothradio_linux.c
680+
src/detection/board/board_nbsd.c
681+
src/detection/bootmgr/bootmgr_nosupport.c
682+
src/detection/brightness/brightness_bsd.c
683+
src/detection/btrfs/btrfs_nosupport.c
684+
src/detection/chassis/chassis_nbsd.c
685+
src/detection/cpu/cpu_bsd.c
686+
src/detection/cpucache/cpucache_nosupport.c
687+
src/detection/cpuusage/cpuusage_nosupport.c
688+
src/detection/cursor/cursor_linux.c
689+
src/detection/disk/disk_nosupport.c
690+
src/detection/dns/dns_linux.c
691+
src/detection/physicaldisk/physicaldisk_nosupport.c
692+
src/detection/physicalmemory/physicalmemory_nosupport.c
693+
src/detection/diskio/diskio_nosupport.c
694+
src/detection/displayserver/linux/displayserver_linux.c
695+
src/detection/displayserver/linux/drm.c
696+
src/detection/displayserver/linux/wayland/wayland.c
697+
src/detection/displayserver/linux/wayland/global-output.c
698+
src/detection/displayserver/linux/wayland/zwlr-output.c
699+
src/detection/displayserver/linux/wayland/kde-output.c
700+
src/detection/displayserver/linux/wayland/wlr-output-management-unstable-v1-protocol.c
701+
src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c
702+
src/detection/displayserver/linux/wayland/kde-output-order-v1-protocol.c
703+
src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c
704+
src/detection/displayserver/linux/wmde.c
705+
src/detection/displayserver/linux/xcb.c
706+
src/detection/displayserver/linux/xlib.c
707+
src/detection/font/font_linux.c
708+
src/detection/gpu/gpu_nosupport.c
709+
src/detection/gpu/gpu_pci.c
710+
src/detection/gtk_qt/gtk.c
711+
src/detection/host/host_nbsd.c
712+
src/detection/lm/lm_linux.c
713+
src/detection/icons/icons_linux.c
714+
src/detection/initsystem/initsystem_linux.c
715+
src/detection/keyboard/keyboard_nosupport.c
716+
src/detection/libc/libc_nosupport.c
717+
src/detection/loadavg/loadavg_bsd.c
718+
src/detection/locale/locale_linux.c
719+
src/detection/localip/localip_linux.c
720+
src/detection/gamepad/gamepad_nosupport.c
721+
src/detection/media/media_linux.c
722+
src/detection/memory/memory_bsd.c
723+
src/detection/mouse/mouse_nosupport.c
724+
src/detection/netio/netio_nosupport.c
725+
src/detection/opengl/opengl_linux.c
726+
src/detection/os/os_nbsd.c
727+
src/detection/packages/packages_nosupport.c
728+
src/detection/poweradapter/poweradapter_nosupport.c
729+
src/detection/processes/processes_nosupport.c
730+
src/detection/gtk_qt/qt.c
731+
src/detection/sound/sound_nosupport.c
732+
src/detection/swap/swap_nosupport.c
733+
src/detection/terminalfont/terminalfont_linux.c
734+
src/detection/terminalshell/terminalshell_linux.c
735+
src/detection/terminalsize/terminalsize_linux.c
736+
src/detection/theme/theme_linux.c
737+
src/detection/tpm/tpm_nosupport.c
738+
src/detection/uptime/uptime_bsd.c
739+
src/detection/users/users_linux.c
740+
src/detection/wallpaper/wallpaper_linux.c
741+
src/detection/wifi/wifi_nosupport.c
742+
src/detection/wm/wm_nosupport.c
743+
src/detection/de/de_linux.c
744+
src/detection/wmtheme/wmtheme_linux.c
745+
src/detection/camera/camera_linux.c
746+
src/detection/zpool/zpool_linux.c
747+
src/util/platform/FFPlatform_unix.c
748+
src/util/binary_linux.c
749+
)
666750
elseif(OpenBSD)
667751
list(APPEND LIBFASTFETCH_SRC
668752
src/common/dbus.c
@@ -1054,6 +1138,9 @@ elseif(OpenBSD)
10541138
target_compile_definitions(libfastfetch PUBLIC _XOPEN_SOURCE=700 _FILE_OFFSET_BITS=64 _BSD_SOURCE)
10551139
elseif(SunOS)
10561140
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 __EXTENSIONS__ _POSIX_C_SOURCE)
1141+
elseif(NetBSD)
1142+
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE)
1143+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-char-subscripts")
10571144
endif()
10581145

10591146
if(HAVE_STATX)

src/common/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void ffListFeatures(void)
245245
#if FF_HAVE_DDCUTIL
246246
"libddcutil\n"
247247
#endif
248-
#if FF_HAVE_ELF || __sun || __FreeBSD__ || __OpenBSD__
248+
#if FF_HAVE_ELF || __sun || __FreeBSD__ || __OpenBSD__ || __NetBSD__
249249
"libelf\n"
250250
#endif
251251
#if FF_HAVE_LIBZFS

src/common/processing_linux.c

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
#elif defined(__sun)
2424
#include <procfs.h>
2525
#elif defined(__OpenBSD__)
26-
#include <sys/param.h>
27-
#include <sys/sysctl.h>
28-
#include <kvm.h>
26+
#include <sys/param.h>
27+
#include <sys/sysctl.h>
28+
#include <kvm.h>
29+
#elif defined(__NetBSD__)
30+
#include <sys/types.h>
31+
#include <sys/sysctl.h>
2932
#endif
3033

3134
enum { FF_PIPE_BUFSIZ = 8192 };
@@ -202,23 +205,35 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
202205
}
203206
}
204207

205-
#elif defined(__FreeBSD__)
208+
#elif defined(__FreeBSD__) || defined(__NetBSD__)
206209

207210
size_t size = ARG_MAX;
208211
FF_AUTO_FREE char* args = malloc(size);
209212

210213
static_assert(ARG_MAX > PATH_MAX, "");
211214

212215
if(exePath && sysctl(
213-
(int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, pid}, 4,
216+
(int[]){CTL_KERN,
217+
#if __FreeBSD__
218+
KERN_PROC,
219+
#else
220+
KERN_PROC_ARGS,
221+
#endif
222+
KERN_PROC_PATHNAME, pid}, 4,
214223
args, &size,
215224
NULL, 0
216225
) == 0)
217226
ffStrbufSetNS(exePath, (uint32_t) (size - 1), args);
218227

219228
size = ARG_MAX;
220229
if(sysctl(
221-
(int[]){CTL_KERN, KERN_PROC, KERN_PROC_ARGS, pid}, 4,
230+
(int[]){CTL_KERN,
231+
#if __FreeBSD__
232+
KERN_PROC, KERN_PROC_ARGS,
233+
#else
234+
KERN_PROC_ARGS, KERN_PROC_ARGV,
235+
#endif
236+
pid}, 4,
222237
args, &size,
223238
NULL, 0
224239
) == 0)
@@ -378,6 +393,34 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
378393
*tty = -1;
379394
}
380395

396+
#elif defined(__NetBSD__)
397+
398+
struct kinfo_proc2 proc;
399+
size_t size = sizeof(proc);
400+
if(sysctl(
401+
(int[]){CTL_KERN, KERN_PROC2, KERN_PROC_PID, pid}, 4,
402+
&proc, &size,
403+
NULL, 0
404+
))
405+
return "sysctl(KERN_PROC_PID) failed";
406+
407+
ffStrbufSetS(name, proc.p_comm);
408+
if (ppid)
409+
*ppid = (pid_t)proc.p_ppid;
410+
if (tty)
411+
{
412+
if (proc.p_flag & P_CONTROLT)
413+
{
414+
const char* ttyName = devname(proc.p_tdev, S_IFCHR);
415+
if (ffStrStartsWith(ttyName, "pts/"))
416+
*tty = (int32_t) strtol(ttyName + strlen("pts/"), NULL, 10);
417+
else
418+
*tty = -1;
419+
}
420+
else
421+
*tty = -1;
422+
}
423+
381424
#elif defined(__sun)
382425
char path[128];
383426
snprintf(path, sizeof(path), "/proc/%d/psinfo", (int) pid);

src/detection/bios/bios_nbsd.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "bios.h"
2+
#include "common/sysctl.h"
3+
#include "util/smbiosHelper.h"
4+
5+
const char* ffDetectBios(FFBiosResult* bios)
6+
{
7+
if (ffSysctlGetString("machdep.dmi.bios-date", &bios->date) == NULL)
8+
ffCleanUpSmbiosValue(&bios->date);
9+
if (ffSysctlGetString("machdep.dmi.bios-version", &bios->version) == NULL)
10+
ffCleanUpSmbiosValue(&bios->version);
11+
if (ffSysctlGetString("machdep.dmi.bios-vendor", &bios->vendor) == NULL)
12+
ffCleanUpSmbiosValue(&bios->vendor);
13+
14+
return NULL;
15+
}

src/detection/board/board_nbsd.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "board.h"
2+
#include "common/sysctl.h"
3+
#include "util/smbiosHelper.h"
4+
5+
const char* ffDetectBoard(FFBoardResult* board)
6+
{
7+
if (ffSysctlGetString("machdep.dmi.board-product", &board->name) == NULL)
8+
ffCleanUpSmbiosValue(&board->name);
9+
if (ffSysctlGetString("machdep.dmi.board-version", &board->version) == NULL)
10+
ffCleanUpSmbiosValue(&board->version);
11+
if (ffSysctlGetString("machdep.dmi.board-vendor", &board->vendor) == NULL)
12+
ffCleanUpSmbiosValue(&board->vendor);
13+
14+
return NULL;
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "chassis.h"
2+
#include "common/sysctl.h"
3+
#include "util/smbiosHelper.h"
4+
5+
const char* ffDetectChassis(FFChassisResult* chassis)
6+
{
7+
if (ffSysctlGetString("machdep.dmi.chassis-type", &chassis->type) == NULL)
8+
ffCleanUpSmbiosValue(&chassis->type);
9+
if (ffSysctlGetString("machdep.dmi.chassis-version", &chassis->version) == NULL)
10+
ffCleanUpSmbiosValue(&chassis->version);
11+
if (ffSysctlGetString("machdep.dmi.chassis-vendor", &chassis->vendor) == NULL)
12+
ffCleanUpSmbiosValue(&chassis->vendor);
13+
14+
return NULL;
15+
}

src/detection/cpu/cpu_bsd.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ static const char* detectThermalTemp(double* current)
2525

2626
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
2727
{
28-
if (ffSysctlGetString("hw.model", &cpu->name))
28+
#if __NetBSD__
29+
if (ffSysctlGetString("machdep.cpu_brand", &cpu->name) != NULL)
30+
return "sysctlbyname(machdep.cpu_brand) failed";
31+
#else
32+
if (ffSysctlGetString("hw.model", &cpu->name) != NULL)
2933
return "sysctlbyname(hw.model) failed";
34+
#endif
3035

3136
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1);
3237
cpu->coresLogical = cpu->coresPhysical;

src/detection/host/host_nbsd.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "host.h"
2+
#include "common/sysctl.h"
3+
#include "util/smbiosHelper.h"
4+
5+
const char* ffDetectHost(FFHostResult* host)
6+
{
7+
const char* error = NULL;
8+
if ((error = ffSysctlGetString("machdep.dmi.system-product", &host->name)))
9+
return error;
10+
ffCleanUpSmbiosValue(&host->name);
11+
if (ffSysctlGetString("machdep.dmi.system-vendor", &host->vendor) == NULL)
12+
ffCleanUpSmbiosValue(&host->vendor);
13+
if (ffSysctlGetString("machdep.dmi.system-version", &host->version) == NULL)
14+
ffCleanUpSmbiosValue(&host->version);
15+
16+
return NULL;
17+
}

src/detection/loadavg/loadavg_bsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <sys/sysctl.h>
44

5-
#if __FreeBSD__ || __OpenBSD__
5+
#if __FreeBSD__ || __OpenBSD__ || __NetBSD__
66
#include <sys/types.h>
77
#include <sys/resource.h>
88
#if __FreeBSD__

0 commit comments

Comments
 (0)