mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
Global: simplifies code
This commit is contained in:
@@ -213,15 +213,11 @@ FF_A_UNUSED static const char* drmGetEdidByConnId(uint32_t connId, uint8_t* edid
|
||||
}
|
||||
|
||||
static const char* drmConnectLibdrm(FFDisplayServerResult* result) {
|
||||
const char* drmDirPath = "/dev/dri/";
|
||||
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(drmDirPath);
|
||||
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/dev/dri/");
|
||||
if (dirp == NULL) {
|
||||
return "opendir(/dev/dri/) failed";
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY pathBuf = ffStrbufCreateA(64);
|
||||
ffStrbufAppendS(&pathBuf, drmDirPath);
|
||||
uint32_t pathLen = pathBuf.length;
|
||||
int drifd = dirfd(dirp);
|
||||
|
||||
int nSuccess = 0;
|
||||
|
||||
@@ -231,21 +227,17 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ffStrbufAppendS(&pathBuf, entry->d_name);
|
||||
|
||||
#if __linux__
|
||||
char powerStatusBuf[512];
|
||||
snprintf(powerStatusBuf, ARRAY_SIZE(powerStatusBuf), "/sys/class/drm/%s/device/power/runtime_status", entry->d_name);
|
||||
|
||||
char buffer[8] = "";
|
||||
if (ffReadFileData(powerStatusBuf, strlen("suspend"), buffer) > 0 && ffStrStartsWith(buffer, "suspend")) {
|
||||
ffStrbufSubstrBefore(&pathBuf, pathLen);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
FF_AUTO_CLOSE_FD int primaryFd = open(pathBuf.chars, O_RDWR | O_CLOEXEC);
|
||||
ffStrbufSubstrBefore(&pathBuf, pathLen);
|
||||
FF_AUTO_CLOSE_FD int primaryFd = openat(drifd, entry->d_name, O_RDWR | O_CLOEXEC);
|
||||
if (primaryFd < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -104,15 +104,11 @@ static const char* drmGetPciinfo(int drmfd, const char* drmId, struct drm_pciinf
|
||||
}
|
||||
|
||||
const char* ffGPUDetectByDrmBSD(const FFGPUOptions* options, FFlist* gpus) {
|
||||
const char* drmDirPath = "/dev/dri/";
|
||||
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(drmDirPath);
|
||||
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/dev/dri/");
|
||||
if (dirp == NULL) {
|
||||
return "opendir(/dev/dri/) failed";
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY pathBuf = ffStrbufCreateA(64);
|
||||
ffStrbufAppendS(&pathBuf, drmDirPath);
|
||||
uint32_t pathLen = pathBuf.length;
|
||||
int drifd = dirfd(dirp);
|
||||
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dirp)) != NULL) {
|
||||
@@ -120,10 +116,7 @@ const char* ffGPUDetectByDrmBSD(const FFGPUOptions* options, FFlist* gpus) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ffStrbufAppendS(&pathBuf, entry->d_name);
|
||||
|
||||
FF_AUTO_CLOSE_FD int fd = open(pathBuf.chars, O_RDWR | O_CLOEXEC);
|
||||
ffStrbufSubstrBefore(&pathBuf, pathLen);
|
||||
FF_AUTO_CLOSE_FD int fd = openat(drifd, entry->d_name, O_RDWR | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user