PDA

View Full Version : [ClanLib 3.0](Maybe also 2.3...) Joystick fix



Zenol
06-15-2013, 03:58 PM
Hi, here it's a really "strange" fix. It's relate to ioctl behavior (on archlinux, kernel 3.2.9, and I do not tested with a joystick due to lack of hardward).

Here is the documentation I found :
https://www.kernel.org/doc/Documentation/input/joystick-api.txt

Clanlib's X11's input_device_provider_linuxjoystick.cpp follow the documentation and use the following call :


char name_cstr[256];
if (ioctl(fd, JSIOCGNAME(sizeof(name_cstr)), name_cstr) < 0)
strncpy(name_cstr, "Unknown", sizeof(name_cstr));


But, in some conditions (do not ask me why and when...), the "name_cstr" field isn't writen by ioctl, althought the function didn't return a negative value. So a fix is :


char name_cstr[256] = {'\0'}; //Initialize the string as an empty C string.
if (ioctl(fd, JSIOCGNAME(sizeof(name_cstr)), name_cstr) < 0)
strncpy(name_cstr, "Unknown", sizeof(name_cstr));


At the same time, I saw some old C in the call of x11 window cpp file, so I wasn't able to keep myself from rewriting it. I saw that string_format is used in the mouse code, so I just used it. Check the patch file.

rombust
06-16-2013, 10:30 PM
humm, interesting. iirc, valgrind complained about that function many many years ago (ClanLib 0.9 time)
I wonder if it's connected...

rombust
06-17-2013, 07:11 AM
Patch applied, many thanks