From b0fd11fcbdb83405180865f5a5afa17ac93eccca Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 18 Jun 2026 10:59:36 +0800 Subject: [PATCH] Global: simplifies code --- src/detection/displayserver/linux/drm.c | 14 +++----------- src/detection/gpu/gpu_bsddrm.c | 13 +++---------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/detection/displayserver/linux/drm.c b/src/detection/displayserver/linux/drm.c index 6b6cfe462..497c783e8 100644 --- a/src/detection/displayserver/linux/drm.c +++ b/src/detection/displayserver/linux/drm.c @@ -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; } diff --git a/src/detection/gpu/gpu_bsddrm.c b/src/detection/gpu/gpu_bsddrm.c index 99bb11af8..6c565cad6 100644 --- a/src/detection/gpu/gpu_bsddrm.c +++ b/src/detection/gpu/gpu_bsddrm.c @@ -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; }