SDL: Check to see if the file exists in the base path before returning it

From 0ffd985972f6a087fc2c847c83cedfdc858fc52f Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 18 May 2022 09:59:12 -0700
Subject: [PATCH] Check to see if the file exists in the base path before
 returning it

---
 test/testutils.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/test/testutils.c b/test/testutils.c
index fa21fe2a87b..e6773ac3a07 100644
--- a/test/testutils.c
+++ b/test/testutils.c
@@ -30,6 +30,7 @@ GetNearbyFilename(const char *file)
     base = SDL_GetBasePath();
 
     if (base != NULL) {
+        SDL_RWops *rw;
         size_t len = SDL_strlen(base) + SDL_strlen(pathsep) + SDL_strlen(file) + 1;
 
         path = SDL_malloc(len);
@@ -42,13 +43,21 @@ GetNearbyFilename(const char *file)
 
         SDL_snprintf(path, len, "%s%s%s", base, pathsep, file);
         SDL_free(base);
-    } else {
-        path = SDL_strdup(file);
-        if (path == NULL) {
-            SDL_OutOfMemory();
+
+        rw = SDL_RWFromFile(path, "rb");
+        if (rw) {
+            SDL_RWclose(rw);
+            return path;
         }
+
+        /* Couldn't find the file in the base path */
+        SDL_free(path);
     }
 
+    path = SDL_strdup(file);
+    if (path == NULL) {
+        SDL_OutOfMemory();
+    }
     return path;
 }