src/filesystem/haiku/SDL_sysfilesystem.cc
author Ryan C. Gordon <icculus@icculus.org>
Thu, 14 Nov 2013 11:51:24 -0500
changeset 7981 6d538bc1b395
parent 7883 src/filesystem/beos/SDL_sysfilesystem.cc@62f562a475e1
child 8093 b43765095a6f
permissions -rw-r--r--
Renamed things named after BeOS to be named after Haiku instead.
icculus@7667
     1
/*
icculus@7667
     2
  Simple DirectMedia Layer
icculus@7667
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
icculus@7667
     4
icculus@7667
     5
  This software is provided 'as-is', without any express or implied
icculus@7667
     6
  warranty.  In no event will the authors be held liable for any damages
icculus@7667
     7
  arising from the use of this software.
icculus@7667
     8
icculus@7667
     9
  Permission is granted to anyone to use this software for any purpose,
icculus@7667
    10
  including commercial applications, and to alter it and redistribute it
icculus@7667
    11
  freely, subject to the following restrictions:
icculus@7667
    12
icculus@7667
    13
  1. The origin of this software must not be misrepresented; you must not
icculus@7667
    14
     claim that you wrote the original software. If you use this software
icculus@7667
    15
     in a product, an acknowledgment in the product documentation would be
icculus@7667
    16
     appreciated but is not required.
icculus@7667
    17
  2. Altered source versions must be plainly marked as such, and must not be
icculus@7667
    18
     misrepresented as being the original software.
icculus@7667
    19
  3. This notice may not be removed or altered from any source distribution.
icculus@7667
    20
*/
icculus@7667
    21
#include "SDL_config.h"
icculus@7667
    22
icculus@7981
    23
#ifdef SDL_FILESYSTEM_HAIKU
icculus@7667
    24
icculus@7667
    25
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
icculus@7667
    26
/* System dependent filesystem routines                                */
icculus@7667
    27
icculus@7667
    28
#include <os/kernel/image.h>
icculus@7667
    29
#include <os/storage/Directory.h>
icculus@7673
    30
#include <os/storage/Entry.h>
icculus@7667
    31
#include <os/storage/Path.h>
icculus@7667
    32
icculus@7667
    33
#include "SDL_error.h"
icculus@7667
    34
#include "SDL_stdinc.h"
icculus@7667
    35
#include "SDL_assert.h"
icculus@7667
    36
#include "SDL_filesystem.h"
icculus@7667
    37
icculus@7667
    38
char *
icculus@7667
    39
SDL_GetBasePath(void)
icculus@7667
    40
{
icculus@7667
    41
    image_info info;
icculus@7667
    42
    int32 cookie = 0;
icculus@7667
    43
icculus@7667
    44
    while (get_next_image_info(0, &cookie, &info) == B_OK) {
icculus@7667
    45
        if (info.type == B_APP_IMAGE) {
icculus@7667
    46
            break;
icculus@7667
    47
        }
icculus@7667
    48
    }
icculus@7667
    49
icculus@7667
    50
    BEntry entry(info.name, true);
icculus@7667
    51
    BPath path;
icculus@7667
    52
    status_t rc = entry.GetPath(&path);  /* (path) now has binary's path. */
icculus@7667
    53
    SDL_assert(rc == B_OK);
icculus@7667
    54
    rc = path.GetParent(&path); /* chop filename, keep directory. */
icculus@7667
    55
    SDL_assert(rc == B_OK);
icculus@7667
    56
    const char *str = path.Path();
icculus@7667
    57
    SDL_assert(str != NULL);
icculus@7667
    58
icculus@7667
    59
    const size_t len = SDL_strlen(str);
icculus@7667
    60
    char *retval = (char *) SDL_malloc(len + 2);
icculus@7667
    61
    if (!retval) {
icculus@7667
    62
        SDL_OutOfMemory();
icculus@7667
    63
        return NULL;
icculus@7667
    64
    }
icculus@7667
    65
icculus@7676
    66
    SDL_memcpy(retval, str, len);
icculus@7667
    67
    retval[len] = '/';
icculus@7667
    68
    retval[len+1] = '\0';
icculus@7667
    69
    return retval;
icculus@7667
    70
}
icculus@7667
    71
icculus@7667
    72
icculus@7667
    73
char *
icculus@7667
    74
SDL_GetPrefPath(const char *org, const char *app)
icculus@7667
    75
{
icculus@7667
    76
    // !!! FIXME: is there a better way to do this?
icculus@7667
    77
    const char *home = SDL_getenv("HOME");
icculus@7667
    78
    const char *append = "config/settings/";
icculus@7883
    79
    const size_t len = SDL_strlen(home) + SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
icculus@7667
    80
    char *retval = (char *) SDL_malloc(len);
icculus@7667
    81
    if (!retval) {
icculus@7667
    82
        SDL_OutOfMemory();
icculus@7667
    83
    } else {
icculus@7883
    84
        SDL_snprintf(retval, len, "%s%s%s/%s/", home, append, org, app);
icculus@7981
    85
        create_directory(retval, 0700);  // Haiku api: creates missing dirs
icculus@7667
    86
    }
icculus@7667
    87
icculus@7667
    88
    return retval;
icculus@7667
    89
}
icculus@7667
    90
icculus@7981
    91
#endif /* SDL_FILESYSTEM_HAIKU */
icculus@7667
    92
icculus@7667
    93
/* vi: set ts=4 sw=4 expandtab: */