src/filesystem/haiku/SDL_sysfilesystem.cc
changeset 7981 6d538bc1b395
parent 7883 62f562a475e1
child 8093 b43765095a6f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/filesystem/haiku/SDL_sysfilesystem.cc	Thu Nov 14 11:51:24 2013 -0500
     1.3 @@ -0,0 +1,93 @@
     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_HAIKU
    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/Entry.h>
    1.34 +#include <os/storage/Path.h>
    1.35 +
    1.36 +#include "SDL_error.h"
    1.37 +#include "SDL_stdinc.h"
    1.38 +#include "SDL_assert.h"
    1.39 +#include "SDL_filesystem.h"
    1.40 +
    1.41 +char *
    1.42 +SDL_GetBasePath(void)
    1.43 +{
    1.44 +    image_info info;
    1.45 +    int32 cookie = 0;
    1.46 +
    1.47 +    while (get_next_image_info(0, &cookie, &info) == B_OK) {
    1.48 +        if (info.type == B_APP_IMAGE) {
    1.49 +            break;
    1.50 +        }
    1.51 +    }
    1.52 +
    1.53 +    BEntry entry(info.name, true);
    1.54 +    BPath path;
    1.55 +    status_t rc = entry.GetPath(&path);  /* (path) now has binary's path. */
    1.56 +    SDL_assert(rc == B_OK);
    1.57 +    rc = path.GetParent(&path); /* chop filename, keep directory. */
    1.58 +    SDL_assert(rc == B_OK);
    1.59 +    const char *str = path.Path();
    1.60 +    SDL_assert(str != NULL);
    1.61 +
    1.62 +    const size_t len = SDL_strlen(str);
    1.63 +    char *retval = (char *) SDL_malloc(len + 2);
    1.64 +    if (!retval) {
    1.65 +        SDL_OutOfMemory();
    1.66 +        return NULL;
    1.67 +    }
    1.68 +
    1.69 +    SDL_memcpy(retval, str, len);
    1.70 +    retval[len] = '/';
    1.71 +    retval[len+1] = '\0';
    1.72 +    return retval;
    1.73 +}
    1.74 +
    1.75 +
    1.76 +char *
    1.77 +SDL_GetPrefPath(const char *org, const char *app)
    1.78 +{
    1.79 +    // !!! FIXME: is there a better way to do this?
    1.80 +    const char *home = SDL_getenv("HOME");
    1.81 +    const char *append = "config/settings/";
    1.82 +    const size_t len = SDL_strlen(home) + SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
    1.83 +    char *retval = (char *) SDL_malloc(len);
    1.84 +    if (!retval) {
    1.85 +        SDL_OutOfMemory();
    1.86 +    } else {
    1.87 +        SDL_snprintf(retval, len, "%s%s%s/%s/", home, append, org, app);
    1.88 +        create_directory(retval, 0700);  // Haiku api: creates missing dirs
    1.89 +    }
    1.90 +
    1.91 +    return retval;
    1.92 +}
    1.93 +
    1.94 +#endif /* SDL_FILESYSTEM_HAIKU */
    1.95 +
    1.96 +/* vi: set ts=4 sw=4 expandtab: */