- Error(ERR_RETURN, "cannot access joystick device '%s'",
- joystick_device_name[joystick_nr]);
- joystick_status = JOYSTICK_OFF;
- return;
+ char *device_name = setup.input[i].joy.device_name;
+
+ /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
+ if (stored_player[i].joystick_fd != -1)
+ {
+ close(stored_player[i].joystick_fd);
+ stored_player[i].joystick_fd = -1;
+ }
+
+ if (!setup.input[i].use_joystick)
+ continue;
+
+ if (access(device_name, R_OK) != 0)
+ {
+ Error(ERR_WARN, "cannot access joystick device '%s'", device_name);
+ continue;
+ }
+
+ if ((stored_player[i].joystick_fd = open(device_name, O_RDONLY)) < 0)
+ {
+ Error(ERR_WARN, "cannot open joystick device '%s'", device_name);
+ continue;
+ }
+
+ joystick_status = JOYSTICK_AVAILABLE;