SDL: Allow opening asset paths starting with "./"

From cc768f3e88bc3506829ad2d0b29a53db642a7769 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 18 Nov 2025 15:29:04 -0800
Subject: [PATCH] Allow opening asset paths starting with "./"

Fixes https://github.com/libsdl-org/SDL/issues/13933
---
 src/core/android/SDL_android.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index 2297fd1228bd7..7623d8bae01ab 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -1873,6 +1873,17 @@ static void Internal_Android_Destroy_AssetManager(void)
     }
 }
 
+static const char *GetAssetPath(const char *path)
+{
+    if (path && path[0] == '.' && path[1] == '/') {
+        path += 2;
+        while (*path == '/') {
+            ++path;
+        }
+    }
+    return path;
+}
+
 bool Android_JNI_FileOpen(void **puserdata, const char *fileName, const char *mode)
 {
     SDL_assert(puserdata != NULL);
@@ -1882,11 +1893,12 @@ bool Android_JNI_FileOpen(void **puserdata, const char *fileName, const char *mo
 
     if (!asset_manager) {
         Internal_Android_Create_AssetManager();
+        if (!asset_manager) {
+            return SDL_SetError("Couldn't create asset manager");
+        }
     }
 
-    if (!asset_manager) {
-        return SDL_SetError("Couldn't create asset manager");
-    }
+    fileName = GetAssetPath(fileName);
 
     asset = AAssetManager_open(asset_manager, fileName, AASSET_MODE_UNKNOWN);
     if (!asset) {
@@ -1944,6 +1956,8 @@ bool Android_JNI_EnumerateAssetDirectory(const char *path, SDL_EnumerateDirector
         }
     }
 
+    path = GetAssetPath(path);
+
     AAssetDir *adir = AAssetManager_openDir(asset_manager, path);
     if (!adir) {
         return SDL_SetError("AAssetManager_openDir failed");
@@ -1969,6 +1983,8 @@ bool Android_JNI_GetAssetPathInfo(const char *path, SDL_PathInfo *info)
         }
     }
 
+    path = GetAssetPath(path);
+
     // this is sort of messy, but there isn't a stat()-like interface to the Assets.
     AAsset *aasset = AAssetManager_open(asset_manager, path, AASSET_MODE_UNKNOWN);
     if (aasset) {  // it's a file!