From 4b6f2a9efaef0bc34dff9187bf9e0a521d033937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 27 Mar 2025 14:40:33 +0800 Subject: [PATCH] Gamepad / Keyboard / Mouse (FreeBSD): break detection earlier --- src/detection/gamepad/gamepad_bsd.c | 8 ++++++-- src/detection/keyboard/keyboard_bsd.c | 7 ++++++- src/detection/mouse/mouse_bsd.c | 8 ++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/detection/gamepad/gamepad_bsd.c b/src/detection/gamepad/gamepad_bsd.c index 21631e9a0..1cc5993ba 100644 --- a/src/detection/gamepad/gamepad_bsd.c +++ b/src/detection/gamepad/gamepad_bsd.c @@ -20,8 +20,12 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) { snprintf(path, ARRAY_SIZE(path), "/dev/uhid%d", i); FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC); - if (fd < 0) continue; - + if (fd < 0) + { + if (errno == ENOENT) + break; // No more devices + continue; // Device not found + } report_desc_t repDesc = hid_get_report_desc(fd); if (!repDesc) continue; diff --git a/src/detection/keyboard/keyboard_bsd.c b/src/detection/keyboard/keyboard_bsd.c index 3d9fb66f5..727e91b02 100644 --- a/src/detection/keyboard/keyboard_bsd.c +++ b/src/detection/keyboard/keyboard_bsd.c @@ -47,7 +47,12 @@ static const char* detectByUsbhid(FFlist* devices) { snprintf(path, ARRAY_SIZE(path), "/dev/uhid%d", i); FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC); - if (fd < 0) continue; + if (fd < 0) + { + if (errno == ENOENT) + break; // No more devices + continue; // Device not found + } report_desc_t repDesc = hid_get_report_desc(fd); if (!repDesc) continue; diff --git a/src/detection/mouse/mouse_bsd.c b/src/detection/mouse/mouse_bsd.c index 5052475bf..3a1f2eb69 100644 --- a/src/detection/mouse/mouse_bsd.c +++ b/src/detection/mouse/mouse_bsd.c @@ -20,8 +20,12 @@ const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */) { snprintf(path, ARRAY_SIZE(path), "/dev/uhid%d", i); FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC); - if (fd < 0) continue; - + if (fd < 0) + { + if (errno == ENOENT) + break; // No more devices + continue; // Device not found + } report_desc_t repDesc = hid_get_report_desc(fd); if (!repDesc) continue;