Commit cbccf5bb5088853bfbff5f22303082950cf8aab4

Sam Lantinga 2021-08-24T17:01:06

Use SDL_GetHint() instead of SDL_getenv() for Linux joystick hints

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, ':');