From 77238767ee7707fedd249624955605ea1ea80f1a Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Mon, 26 Aug 2013 20:54:26 +0200 Subject: [PATCH] Improved joystick detection performances on Linux (avoids endless calls to open when a joystick node cannot be open) --- src/SFML/Window/Linux/JoystickImpl.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/SFML/Window/Linux/JoystickImpl.cpp b/src/SFML/Window/Linux/JoystickImpl.cpp index ccec0a31..0ea1ac23 100644 --- a/src/SFML/Window/Linux/JoystickImpl.cpp +++ b/src/SFML/Window/Linux/JoystickImpl.cpp @@ -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; + } } }