Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
authorSam Lantinga <slouken@libsdl.org>
Mon, 11 Aug 2014 17:25:53 -0700
changeset 905418d34edc79ac
parent 9053 3b9a57b45288
child 9055 868b523403e0
Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Android.mk
include/SDL_config_android.h
src/filesystem/android/SDL_sysfilesystem.c
     1.1 --- a/Android.mk	Mon Aug 11 17:24:54 2014 -0700
     1.2 +++ b/Android.mk	Mon Aug 11 17:25:53 2014 -0700
     1.3 @@ -34,7 +34,7 @@
     1.4  	$(wildcard $(LOCAL_PATH)/src/loadso/dlopen/*.c) \
     1.5  	$(wildcard $(LOCAL_PATH)/src/power/*.c) \
     1.6  	$(wildcard $(LOCAL_PATH)/src/power/android/*.c) \
     1.7 -	$(wildcard $(LOCAL_PATH)/src/filesystem/dummy/*.c) \
     1.8 +	$(wildcard $(LOCAL_PATH)/src/filesystem/android/*.c) \
     1.9  	$(wildcard $(LOCAL_PATH)/src/render/*.c) \
    1.10  	$(wildcard $(LOCAL_PATH)/src/render/*/*.c) \
    1.11  	$(wildcard $(LOCAL_PATH)/src/stdlib/*.c) \
     2.1 --- a/include/SDL_config_android.h	Mon Aug 11 17:24:54 2014 -0700
     2.2 +++ b/include/SDL_config_android.h	Mon Aug 11 17:25:53 2014 -0700
     2.3 @@ -141,7 +141,7 @@
     2.4  /* Enable system power support */
     2.5  #define SDL_POWER_ANDROID 1
     2.6  
     2.7 -/* !!! FIXME: what does Android do for filesystem stuff? */
     2.8 -#define SDL_FILESYSTEM_DUMMY   1
     2.9 +/* Enable the filesystem driver */
    2.10 +#define SDL_FILESYSTEM_ANDROID   1
    2.11  
    2.12  #endif /* _SDL_config_android_h */
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/filesystem/android/SDL_sysfilesystem.c	Mon Aug 11 17:25:53 2014 -0700
     3.3 @@ -0,0 +1,62 @@
     3.4 +/*
     3.5 +  Simple DirectMedia Layer
     3.6 +  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
     3.7 +
     3.8 +  This software is provided 'as-is', without any express or implied
     3.9 +  warranty.  In no event will the authors be held liable for any damages
    3.10 +  arising from the use of this software.
    3.11 +
    3.12 +  Permission is granted to anyone to use this software for any purpose,
    3.13 +  including commercial applications, and to alter it and redistribute it
    3.14 +  freely, subject to the following restrictions:
    3.15 +
    3.16 +  1. The origin of this software must not be misrepresented; you must not
    3.17 +     claim that you wrote the original software. If you use this software
    3.18 +     in a product, an acknowledgment in the product documentation would be
    3.19 +     appreciated but is not required.
    3.20 +  2. Altered source versions must be plainly marked as such, and must not be
    3.21 +     misrepresented as being the original software.
    3.22 +  3. This notice may not be removed or altered from any source distribution.
    3.23 +*/
    3.24 +#include "../../SDL_internal.h"
    3.25 +
    3.26 +#ifdef SDL_FILESYSTEM_ANDROID
    3.27 +
    3.28 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    3.29 +/* System dependent filesystem routines                                */
    3.30 +
    3.31 +#include <unistd.h>
    3.32 +#include <errno.h>
    3.33 +
    3.34 +#include "SDL_error.h"
    3.35 +#include "SDL_filesystem.h"
    3.36 +#include "SDL_system.h"
    3.37 +
    3.38 +
    3.39 +char *
    3.40 +SDL_GetBasePath(void)
    3.41 +{
    3.42 +    /* The current working directory is / on Android */
    3.43 +    return NULL;
    3.44 +}
    3.45 +
    3.46 +char *
    3.47 +SDL_GetPrefPath(const char *org, const char *app)
    3.48 +{
    3.49 +    const char *path = SDL_AndroidGetInternalStoragePath();
    3.50 +    if (path) {
    3.51 +        size_t pathlen = SDL_strlen(path)+2;
    3.52 +        char *fullpath = (char *)SDL_malloc(pathlen);
    3.53 +        if (!fullpath) {
    3.54 +            SDL_OutOfMemory();
    3.55 +            return NULL;
    3.56 +        }
    3.57 +        SDL_snprintf(fullpath, pathlen, "%s/", path);
    3.58 +        return fullpath;
    3.59 +    }
    3.60 +    return NULL;
    3.61 +}
    3.62 +
    3.63 +#endif /* SDL_FILESYSTEM_ANDROID */
    3.64 +
    3.65 +/* vi: set ts=4 sw=4 expandtab: */