Skip to content

Commit 4b6f2a9

Browse files
committed
Gamepad / Keyboard / Mouse (FreeBSD): break detection earlier
1 parent bdaf303 commit 4b6f2a9

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/detection/gamepad/gamepad_bsd.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
2020
{
2121
snprintf(path, ARRAY_SIZE(path), "/dev/uhid%d", i);
2222
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
23-
if (fd < 0) continue;
24-
23+
if (fd < 0)
24+
{
25+
if (errno == ENOENT)
26+
break; // No more devices
27+
continue; // Device not found
28+
}
2529
report_desc_t repDesc = hid_get_report_desc(fd);
2630
if (!repDesc) continue;
2731

src/detection/keyboard/keyboard_bsd.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ static const char* detectByUsbhid(FFlist* devices)
4747
{
4848
snprintf(path, ARRAY_SIZE(path), "/dev/uhid%d", i);
4949
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
50-
if (fd < 0) continue;
50+
if (fd < 0)
51+
{
52+
if (errno == ENOENT)
53+
break; // No more devices
54+
continue; // Device not found
55+
}
5156

5257
report_desc_t repDesc = hid_get_report_desc(fd);
5358
if (!repDesc) continue;

src/detection/mouse/mouse_bsd.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */)
2020
{
2121
snprintf(path, ARRAY_SIZE(path), "/dev/uhid%d", i);
2222
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
23-
if (fd < 0) continue;
24-
23+
if (fd < 0)
24+
{
25+
if (errno == ENOENT)
26+
break; // No more devices
27+
continue; // Device not found
28+
}
2529
report_desc_t repDesc = hid_get_report_desc(fd);
2630
if (!repDesc) continue;
2731

0 commit comments

Comments
 (0)