Android: Allow SDL_IOFromFile to open content:// URI. (#9696)

This commit is contained in:
Miku AuahDark
2024-05-07 00:05:49 +08:00
committed by GitHub
parent 61c99c0da7
commit 33ae7e38d6
6 changed files with 99 additions and 3 deletions

View File

@@ -54,6 +54,7 @@ struct SDL_IOStream
#endif /* SDL_PLATFORM_3DS */
#ifdef SDL_PLATFORM_ANDROID
#include <unistd.h>
#include "../core/android/SDL_android.h"
#endif
@@ -558,6 +559,22 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode)
}
return SDL_IOFromFP(fp, 1);
}
} else if (SDL_strncmp(file, "content://", 10) == 0) {
/* Try opening content:// URI */
int fd = Android_JNI_OpenFileDescriptor(file, mode);
if (fd == -1) {
/* SDL error is already set. */
return NULL;
}
FILE *fp = fdopen(fd, mode);
if (!fp) {
close(fd);
SDL_SetError("Unable to open file descriptor (%d) from URI %s", fd, file);
return NULL;
}
return SDL_IOFromFP(fp, SDL_TRUE);
} else {
/* Try opening it from internal storage if it's a relative path */
// !!! FIXME: why not just "char path[PATH_MAX];"