mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 00:03:58 +01:00
41 lines
932 B
C
41 lines
932 B
C
#include "common/kmod.h"
|
|
#include "common/strutil.h"
|
|
|
|
#include <sys/module.h>
|
|
#include <sys/param.h>
|
|
|
|
typedef struct [[gnu::packed]] FFNbsdModList {
|
|
int len;
|
|
modstat_t mods[];
|
|
} FFNbsdModList;
|
|
|
|
bool ffKmodLoaded(const char* modName) {
|
|
static FFNbsdModList* list = nullptr;
|
|
|
|
if (list == nullptr) {
|
|
struct iovec iov = {};
|
|
|
|
for (size_t len = 8192;; len = iov.iov_len) {
|
|
iov.iov_len = len;
|
|
iov.iov_base = realloc(iov.iov_base, len);
|
|
if (modctl(MODCTL_STAT, &iov) < 0) {
|
|
free(iov.iov_base);
|
|
return true; // ignore errors
|
|
}
|
|
|
|
if (len >= iov.iov_len) {
|
|
break;
|
|
}
|
|
}
|
|
list = (FFNbsdModList*) iov.iov_base;
|
|
}
|
|
|
|
for (int i = 0; i < list->len; i++) {
|
|
if (ffStrEquals(list->mods[i].ms_name, modName)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|