src/filesystem/beos/SDL_sysfilesystem.cc
changeset 7667 be1cc6f55840
child 7673 e3d59fb413ad
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/filesystem/beos/SDL_sysfilesystem.cc	Tue Aug 20 19:57:11 2013 -0400
     1.3 @@ -0,0 +1,92 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +#include "SDL_config.h"
    1.25 +
    1.26 +#ifdef SDL_FILESYSTEM_BEOS
    1.27 +
    1.28 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    1.29 +/* System dependent filesystem routines                                */
    1.30 +
    1.31 +#include <os/kernel/image.h>
    1.32 +#include <os/storage/Directory.h>
    1.33 +#include <os/storage/Path.h>
    1.34 +
    1.35 +#include "SDL_error.h"
    1.36 +#include "SDL_stdinc.h"
    1.37 +#include "SDL_assert.h"
    1.38 +#include "SDL_filesystem.h"
    1.39 +
    1.40 +char *
    1.41 +SDL_GetBasePath(void)
    1.42 +{
    1.43 +    image_info info;
    1.44 +    int32 cookie = 0;
    1.45 +
    1.46 +    while (get_next_image_info(0, &cookie, &info) == B_OK) {
    1.47 +        if (info.type == B_APP_IMAGE) {
    1.48 +            break;
    1.49 +        }
    1.50 +    }
    1.51 +
    1.52 +    BEntry entry(info.name, true);
    1.53 +    BPath path;
    1.54 +    status_t rc = entry.GetPath(&path);  /* (path) now has binary's path. */
    1.55 +    SDL_assert(rc == B_OK);
    1.56 +    rc = path.GetParent(&path); /* chop filename, keep directory. */
    1.57 +    SDL_assert(rc == B_OK);
    1.58 +    const char *str = path.Path();
    1.59 +    SDL_assert(str != NULL);
    1.60 +
    1.61 +    const size_t len = SDL_strlen(str);
    1.62 +    char *retval = (char *) SDL_malloc(len + 2);
    1.63 +    if (!retval) {
    1.64 +        SDL_OutOfMemory();
    1.65 +        return NULL;
    1.66 +    }
    1.67 +
    1.68 +    SDL_strcpy(retval, str);
    1.69 +    retval[len] = '/';
    1.70 +    retval[len+1] = '\0';
    1.71 +    return retval;
    1.72 +}
    1.73 +
    1.74 +
    1.75 +char *
    1.76 +SDL_GetPrefPath(const char *org, const char *app)
    1.77 +{
    1.78 +    // !!! FIXME: is there a better way to do this?
    1.79 +    const char *home = SDL_getenv("HOME");
    1.80 +    const char *append = "config/settings/";
    1.81 +    const size_t len = SDL_strlen(home) + SDL_strlen(append) + SDL_strlen(app) + 2;
    1.82 +    char *retval = (char *) SDL_malloc(len);
    1.83 +    if (!retval) {
    1.84 +        SDL_OutOfMemory();
    1.85 +    } else {
    1.86 +        SDL_snprintf(retval, len, "%s%s%s/", home, append, app);
    1.87 +        create_directory(retval, 0700);  // BeOS api: creates missing dirs
    1.88 +    }
    1.89 +
    1.90 +    return retval;
    1.91 +}
    1.92 +
    1.93 +#endif /* SDL_FILESYSTEM_BEOS */
    1.94 +
    1.95 +/* vi: set ts=4 sw=4 expandtab: */