src/filesystem/android/SDL_sysfilesystem.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 11 Aug 2014 17:25:53 -0700
changeset 9054 18d34edc79ac
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9054
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
  Simple DirectMedia Layer
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     3
  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
  This software is provided 'as-is', without any express or implied
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
  arising from the use of this software.
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
  freely, subject to the following restrictions:
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
     claim that you wrote the original software. If you use this software
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
     appreciated but is not required.
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
     misrepresented as being the original software.
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "../../SDL_internal.h"
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
#ifdef SDL_FILESYSTEM_ANDROID
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
/* System dependent filesystem routines                                */
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include <unistd.h>
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include <errno.h>
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
#include "SDL_error.h"
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#include "SDL_filesystem.h"
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include "SDL_system.h"
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
char *
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
SDL_GetBasePath(void)
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
{
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
    /* The current working directory is / on Android */
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
    return NULL;
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
}
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
char *
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
SDL_GetPrefPath(const char *org, const char *app)
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
{
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
    const char *path = SDL_AndroidGetInternalStoragePath();
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
    if (path) {
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
        size_t pathlen = SDL_strlen(path)+2;
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
        char *fullpath = (char *)SDL_malloc(pathlen);
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
        if (!fullpath) {
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
            SDL_OutOfMemory();
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
            return NULL;
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
        }
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
        SDL_snprintf(fullpath, pathlen, "%s/", path);
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
        return fullpath;
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
    }
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
    return NULL;
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
}
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
#endif /* SDL_FILESYSTEM_ANDROID */
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
18d34edc79ac Implemented SDL_GetPrefPath() on Android - it returns the path used by SDL_AndroidGetInternalStoragePath()
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
/* vi: set ts=4 sw=4 expandtab: */