master ohmu/fastfetch-openbsd / src / common / impl / kmod_linux.c
ohmu  ·  2026-10-15
 1#include "common/kmod.h"
 2#include "common/io.h"
 3
 4bool ffKmodLoaded(const char* modName) {
 5    static FFstrbuf modules;
 6    if (modules.chars == nullptr) {
 7        ffStrbufInitS(&modules, "\n");
 8        ffAppendFileBuffer("/proc/modules", &modules);
 9    }
10
11    if (modules.length == 0) {
12        return false;
13    }
14
15    uint32_t len = (uint32_t) strlen(modName);
16    if (len > 250) {
17        return false;
18    }
19
20    char temp[256];
21    temp[0] = '\n';
22    memcpy(temp + 1, modName, len);
23    temp[1 + len] = ' ';
24    return memmem(modules.chars, modules.length, temp, len + 2) != nullptr;
25}