Improved joystick detection performances on Linux (avoids endless calls to open when a joystick node cannot be open)

This commit is contained in:
Laurent Gomila 2013-08-26 20:54:26 +02:00
parent 5ffe258320
commit 77238767ee

View File

@ -46,8 +46,17 @@ namespace
{
char name[32];
std::snprintf(name, sizeof(name), "/dev/input/js%u", i);
struct stat info;
plugged[i] = (stat(name, &info) == 0);
int file = ::open(name, O_RDONLY);
if (file >= 0)
{
plugged[i] = true;
::close(file);
}
else
{
plugged[i] = false;
}
}
}