mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-10 07:00:08 +01:00
Global: make it compile on NetBSD
Doesn't work yet.
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
@@ -23,9 +23,12 @@
|
||||
#elif defined(__sun)
|
||||
#include <procfs.h>
|
||||
#elif defined(__OpenBSD__)
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <kvm.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <kvm.h>
|
||||
#elif defined(__NetBSD__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#if __FreeBSD__ || __OpenBSD__
|
||||
#if __FreeBSD__ || __OpenBSD__ || __NetBSD__
|
||||
#include <sys/types.h>
|
||||
#include <sys/resource.h>
|
||||
#if __FreeBSD__
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <linux/if.h>
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
|
||||
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
|
||||
#include <net/if_media.h>
|
||||
#include <net/if_dl.h>
|
||||
#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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "os.h"
|
||||
|
||||
void ffDetectOSImpl(FFOSResult* os)
|
||||
{
|
||||
ffStrbufSetStatic(&os->name, "NetBSD");
|
||||
ffStrbufSet(&os->version, &instance.state.platform.sysinfo.release);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "processes.h"
|
||||
|
||||
const char* ffDetectProcesses(uint32_t* result)
|
||||
{
|
||||
return "Not supported on this platform";
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <paths.h>
|
||||
#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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#ifdef __APPLE__
|
||||
#include <libproc.h>
|
||||
#include <sys/sysctl.h>
|
||||
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
|
||||
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
|
||||
#include <sys/sysctl.h>
|
||||
#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)
|
||||
|
||||
Reference in New Issue
Block a user