aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/linux/src/native/joystickInterface.cpp
diff options
context:
space:
mode:
authorendolf <[email protected]>2005-10-30 21:56:14 +0000
committerendolf <[email protected]>2005-10-30 21:56:14 +0000
commitb46e6aebe45b6cf9b664ac27d3375c93521a3a35 (patch)
treeba82d547e182f116a1615dbaa831102e3c1f32c6 /plugins/linux/src/native/joystickInterface.cpp
parenta25f205e163ebf7009d8076cfe063b260881c9e3 (diff)
3 Changes
When there are no device files found, jinput won't try to read the 0th one. When no js* devices are found in /dev/input it will look in /dev Try to free some of the memory created in the init process git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@126 e343933a-64c8-49c5-92b1-88f2ce3e89e8
Diffstat (limited to 'plugins/linux/src/native/joystickInterface.cpp')
-rw-r--r--plugins/linux/src/native/joystickInterface.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/plugins/linux/src/native/joystickInterface.cpp b/plugins/linux/src/native/joystickInterface.cpp
index dc4f274..da96a61 100644
--- a/plugins/linux/src/native/joystickInterface.cpp
+++ b/plugins/linux/src/native/joystickInterface.cpp
@@ -51,9 +51,16 @@ int jsFileFilter(const struct direct *entry) {
int jsGetDeviceFiles(char ***filenames) {
struct direct **files;
int num_files, i;
- char dirName[] = {"/dev/input"};
+ char dirName[12];
+
+ sprintf(dirName, "/dev/input");
num_files = scandir(dirName, &files, &jsFileFilter, alphasort);
+
+ if(num_files==0) {
+ sprintf(dirName, "/dev");
+ num_files = scandir(dirName, &files, &jsFileFilter, alphasort);
+ }
*filenames = (char **)malloc(num_files * sizeof(char *));
@@ -80,6 +87,12 @@ int jsInit() {
return -1;
}
+ if(numDeviceFiles==0) {
+ jsNumDevices = 0;
+ jsInited=1;
+ return 0;
+ }
+
if ((fd = open(deviceFileNames[0], O_RDONLY)) <0) {
jsNumDevices = 0;
jsInited=1;
@@ -100,13 +113,14 @@ int jsInit() {
jsNumDevices = 0;
for(i=0;i<numDeviceFiles;i++) {
JoystickDevice *tempDevice = new JoystickDevice(deviceFileNames[i]);
+ // The device has a copy of the name, free the memory
+ free(deviceFileNames[i]);
if(tempDevice->isValidDevice()==1) {
tempDeviceList[i] = tempDevice;
jsNumDevices++;
}
}
- int highDeviceCountNumber = i;
int jsTempDeviceCount = 0;
// Now we know for certain which devices are open, we can take notes
jsDeviceList = (Device **)malloc(jsNumDevices * sizeof(Device *));
@@ -118,6 +132,9 @@ int jsInit() {
//printf("Copied joystick %d to %d\n", jsTempDeviceCount, i);
jsTempDeviceCount++;
}
+
+ // Free the file names array, which should now be free anyway.
+ free(deviceFileNames);
jsInited=1;