summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Hlusiak <saschahlusiak@arcor.de>2007-04-07 14:10:01 -0400
committerSascha Hlusiak <saschahlusiak@arcor.de>2007-04-07 14:10:01 -0400
commit7676d3c519a9190e3c7f9ed2c9abec8e95752c36 (patch)
tree2387a96beb886b41e5cd0e6d9e32bf0d51175395
parentd64b3bf18f09d893a219732225f3b327bd70e785 (diff)
Fixed wrong type in ioctl call for detecting buttons and axes
The ioctl call for reading the number of buttons and axes expects an unsigned char as parameter, not an int. Worked in Linux but not in FreeBSD. Changed to unsigned char though and added a check, if buttons and axes are more than MAXBUTTONS/MAXAXES.
-rw-r--r--src/jstk.c4
-rw-r--r--src/jstk.h2
-rw-r--r--src/linux_jstk.c4
3 files changed, 6 insertions, 4 deletions
diff --git a/src/jstk.c b/src/jstk.c
index 783a98b..d45c32a 100644
--- a/src/jstk.c
+++ b/src/jstk.c
@@ -295,11 +295,9 @@ jstkDeviceControlProc(DeviceIntPtr pJstk,
break;
case DEVICE_ON:
- i = jstkOpenDevice(priv);
-
DBG(1, ErrorF("jstkDeviceControlProc what=ON name=%s\n", priv->device));
- if (i != -1)
+ if (jstkOpenDevice(priv) != -1)
{
pJstk->public.on = TRUE;
local->fd = priv->fd;
diff --git a/src/jstk.h b/src/jstk.h
index f24975f..49b4772 100644
--- a/src/jstk.h
+++ b/src/jstk.h
@@ -114,7 +114,7 @@ typedef struct
float temp;
enum JOYSTICKMAPPING mapping;
}button[MAXBUTTONS]; /* Configuration per button */
- int axes, buttons; /* Number of axes and buttons */
+ unsigned char axes, buttons; /* Number of axes and buttons */
} JoystickDevRec, *JoystickDevPtr;
diff --git a/src/linux_jstk.c b/src/linux_jstk.c
index d5757f8..8ff9a09 100644
--- a/src/linux_jstk.c
+++ b/src/linux_jstk.c
@@ -28,6 +28,7 @@
#include <unistd.h>
#include <sys/types.h>
+#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
@@ -82,12 +83,15 @@ jstkOpenDevice(JoystickDevPtr joystick)
close(joystick->fd);
return -1;
}
+ if (joystick->axes > 32) joystick->axes = 32;
+
if (ioctl(joystick->fd, JSIOCGBUTTONS, &joystick->buttons) == -1) {
xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", joystick->device,
strerror(errno));
close(joystick->fd);
return -1;
}
+ if (joystick->buttons > 32) joystick->buttons = 32;
{
if (ioctl(joystick->fd, JSIOCGNAME(128), joy_name) == -1) {