mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-11 06:28:24 +02:00
Android: Allow SDL_IOFromFile to open content:// URI. (#9696)
This commit is contained in:
@@ -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];"
|
||||
|
||||
Reference in New Issue
Block a user