From 4a3e5fc54513634c977c8b8acf7b4cf646285cbf Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 2 Nov 2012 03:08:40 -0700 Subject: [PATCH] Try opening relative path files from internal storage. I'm not falling back to external storage because the application should be aware of whether external storage is available and choose whether or not to use it. --- src/file/SDL_rwops.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/file/SDL_rwops.c b/src/file/SDL_rwops.c index 4a4cda23a..e2a9bf16b 100644 --- a/src/file/SDL_rwops.c +++ b/src/file/SDL_rwops.c @@ -429,13 +429,28 @@ SDL_RWFromFile(const char *file, const char *mode) #if defined(ANDROID) #ifdef HAVE_STDIO_H /* Try to open the file on the filesystem first */ - { + if (*file == '/') { FILE *fp = fopen(file, mode); if (fp) { return SDL_RWFromFP(fp, 1); } + } else { + /* Try opening it from internal storage if it's a relative path */ + char *path; + FILE *fp; + + path = SDL_stack_alloc(char, PATH_MAX); + if (path) { + SDL_snprintf(path, PATH_MAX, "%s/%s", + SDL_AndroidGetInternalStoragePath(), file); + fp = fopen(path, mode); + SDL_stack_free(path); + if (fp) { + return SDL_RWFromFP(fp, 1); + } + } } -#endif +#endif /* HAVE_STDIO_H */ /* Try to open the file from the asset system */ rwops = SDL_AllocRW();