Use SDL_GetHint() instead of SDL_getenv() for Linux joystick hints
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c
index 001db4c..af21d79 100644
--- a/src/joystick/linux/SDL_sysjoystick.c
+++ b/src/joystick/linux/SDL_sysjoystick.c
@@ -627,14 +627,16 @@ LINUX_JoystickDetect(void)
static int
LINUX_JoystickInit(void)
{
+ const char *devices = SDL_GetHint("SDL_JOYSTICK_DEVICE");
+
#if SDL_USE_LIBUDEV
if (enumeration_method == ENUMERATION_UNSET) {
- if (SDL_getenv("SDL_JOYSTICK_DISABLE_UDEV") != NULL) {
+ if (!SDL_GetHintBoolean("SDL_JOYSTICK_DISABLE_UDEV", SDL_FALSE)) {
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
"udev disabled by SDL_JOYSTICK_DISABLE_UDEV");
enumeration_method = ENUMERATION_FALLBACK;
- }
- else if (access("/.flatpak-info", F_OK) == 0
+
+ } else if (access("/.flatpak-info", F_OK) == 0
|| access("/run/host/container-manager", F_OK) == 0) {
/* Explicitly check `/.flatpak-info` because, for old versions of
* Flatpak, this was the only available way to tell if we were in
@@ -642,8 +644,8 @@ LINUX_JoystickInit(void)
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
"Container detected, disabling udev integration");
enumeration_method = ENUMERATION_FALLBACK;
- }
- else {
+
+ } else {
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
"Using udev for joystick device discovery");
enumeration_method = ENUMERATION_LIBUDEV;
@@ -652,9 +654,9 @@ LINUX_JoystickInit(void)
#endif
/* First see if the user specified one or more joysticks to use */
- if (SDL_getenv("SDL_JOYSTICK_DEVICE") != NULL) {
+ if (devices != NULL) {
char *envcopy, *envpath, *delim;
- envcopy = SDL_strdup(SDL_getenv("SDL_JOYSTICK_DEVICE"));
+ envcopy = SDL_strdup(devices);
envpath = envcopy;
while (envpath != NULL) {
delim = SDL_strchr(envpath, ':');