Allow opening joysticks that are read-only on Linux

Fixes https://github.com/libsdl-org/SDL/issues/4713
main
Sam Lantinga 2021-11-07 13:11:29 -08:00
parent 0323d983c6
commit b8c00bf914
1 changed files with 6 additions and 1 deletions

View File

@ -963,7 +963,12 @@ PrepareJoystickHwdata(SDL_Joystick *joystick, SDL_joylist_item *item)
&joystick->naxes, &joystick->naxes,
&joystick->nhats); &joystick->nhats);
} else { } else {
const int fd = open(item->path, O_RDWR | O_CLOEXEC, 0); /* Try read-write first, so we can do rumble */
int fd = open(item->path, O_RDWR | O_CLOEXEC, 0);
if (fd < 0) {
/* Try read-only again, at least we'll get events in this case */
fd = open(item->path, O_RDONLY | O_CLOEXEC, 0);
}
if (fd < 0) { if (fd < 0) {
return SDL_SetError("Unable to open %s", item->path); return SDL_SetError("Unable to open %s", item->path);
} }