A couple of fixes in fg_joystick_x11.c identified in bug report #249

- The correct way to set the O_NONBLOCK flag, is to OR that flag with existing
  flags. Previously we were overriding everything else and setting the flags
  value to O_NONBLOCK directly. Unlikely to cause a problem because we probably
  don't have any other flags in the newly opened file descriptor, but strictly
  spaking it was incorrect.
- If ioctl JSIOCGAXES and JSIOCGBUTTONS could fail, as it stands, it would
  clobber the value of joy->num_axes/joy->num_buttons. It can't fail, but maybe
  in the future who knows. Let's be safe.



git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1848 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
jtsiomb 2019-09-11 13:24:28 +00:00
parent 2239d6c54d
commit 796b7d2f56

View File

@ -599,12 +599,12 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
* to the upper byte of an uninitialized word doesn't work.
* 9 April 2003
*/
ioctl( joy->pJoystick.fd, JSIOCGAXES, &u );
joy->num_axes = u;
ioctl( joy->pJoystick.fd, JSIOCGBUTTONS, &u );
joy->num_buttons = u;
if(ioctl(joy->pJoystick.fd, JSIOCGAXES, &u) != -1)
joy->num_axes = u;
if(ioctl(joy->pJoystick.fd, JSIOCGBUTTONS, &u) != -1)
joy->num_buttons = u;
ioctl( joy->pJoystick.fd, JSIOCGNAME( sizeof( joy->name ) ), joy->name );
fcntl( joy->pJoystick.fd, F_SETFL, O_NONBLOCK );
fcntl(joy->pJoystick.fd, F_SETFL, fcntl(joy->pJoystick.fd, F_GETFL) | O_NONBLOCK);
# endif
/*